fix(Datepicker): navigate to the clicked decade in decades view#1681
fix(Datepicker): navigate to the clicked decade in decades view#1681farhan523 wants to merge 1 commit into
Conversation
Clicking a decade in the decades view computed the new view date as an offset from the selected date's year (addYears(viewDate, year - selectedDate.getFullYear())), which lands in the wrong decade whenever the view date differs from the selected date, and does nothing at all when no date is selected. Use the already-computed date within the clicked decade directly, matching how the years view handles selection. Adds a regression test covering navigation between decades and a changeset for a patch release. Fixes themesberg#1516
🦋 Changeset detectedLatest commit: 1ca40fa The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@farhan523 is attempting to deploy a commit to the Bergside Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR fixes the Datepicker decades view so clicking a decade always sets the view date to the clicked decade's computed date, rather than conditionally computing it relative to the selected date. Includes an updated test and a changeset entry. ChangesDecades View Fix
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Clicking a decade in the Datepicker's decades view often shows the years of a different decade than the one clicked (reproducible on the docs page as well).
Root cause
DatepickerViewsDecadescomputed the new view date as an offset from the selected date's year:This is only correct when the view date happens to be in the same year as the selected date. As soon as the user navigates around (e.g. picks a year, then goes back up to the decades view), the offset lands in the wrong decade. And when no date is selected at all,
setViewDateis never called, so clicking any decade just re-displays the current one — e.g. clicking 1990 and seeing 2020, exactly as reported.Fix
Use the already-computed
newDate(a date within the clicked decade) directly:This mirrors how
DatepickerViewsYearsalready handles clicks and fixes both the wrong-decade and the no-selection cases.Tests
Added a regression test that navigates the view (but not the selection) to a different decade and asserts the years view shows the decade that was clicked. It fails on
main(1970 - 1981instead of2000 - 2011) and passes with this fix. All 16 Datepicker tests pass.A changeset for a patch release is included.
Related issues
Fixes #1516
No breaking API or theme changes.
Summary by CodeRabbit