Skip to content

fix(Datepicker): navigate to the clicked decade in decades view#1681

Open
farhan523 wants to merge 1 commit into
themesberg:mainfrom
farhan523:fix/datepicker-decades-view
Open

fix(Datepicker): navigate to the clicked decade in decades view#1681
farhan523 wants to merge 1 commit into
themesberg:mainfrom
farhan523:fix/datepicker-decades-view

Conversation

@farhan523

@farhan523 farhan523 commented Jul 6, 2026

Copy link
Copy Markdown

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

DatepickerViewsDecades computed the new view date as an offset from the selected date's year:

selectedDate && setViewDate(addYears(viewDate, year - selectedDate.getFullYear()));

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, setViewDate is 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:

setViewDate(newDate);

This mirrors how DatepickerViewsYears already 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 - 1981 instead of 2000 - 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

  • Bug Fixes
    • Fixed decade navigation in the date picker so selecting a decade always opens the matching year range.
    • Resolved an issue where clicking a decade could do nothing when no date was selected.
    • Improved the decades overlay so its title and displayed range stay in sync while navigating.

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-bot

changeset-bot Bot commented Jul 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1ca40fa

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
flowbite-react Patch

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

@vercel

vercel Bot commented Jul 6, 2026

Copy link
Copy Markdown

@farhan523 is attempting to deploy a commit to the Bergside Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d6c33d19-c395-4f74-afc3-f2d661f3298e

📥 Commits

Reviewing files that changed from the base of the PR and between 85319bd and 1ca40fa.

📒 Files selected for processing (3)
  • .changeset/eighty-hoops-shake.md
  • packages/ui/src/components/Datepicker/Datepicker.test.tsx
  • packages/ui/src/components/Datepicker/Views/Decades.tsx

📝 Walkthrough

Walkthrough

This 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.

Changes

Decades View Fix

Layer / File(s) Summary
Fix decade click handler and add coverage
packages/ui/src/components/Datepicker/Views/Decades.tsx, packages/ui/src/components/Datepicker/Datepicker.test.tsx, .changeset/eighty-hoops-shake.md
Decade button click now always calls setViewDate(newDate) for the clicked decade instead of conditionally computing an offset from selectedDate; test verifies decade-year range title updates correctly through navigation and selection; changeset documents the patch fix.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • themesberg/flowbite-react#1452: Both PRs modify the decades view's decade/date click handling logic in Decades.tsx and corresponding Datepicker tests.

Suggested labels: :bug: bug

Suggested reviewers: rluders, teddythinh

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states the main fix: clicking a decade now navigates to that decade in the Datepicker decades view.
Linked Issues check ✅ Passed The code and regression test address #1516 by using the clicked decade directly, which matches the expected decades-view behavior.
Out of Scope Changes check ✅ Passed The test and changeset are directly tied to the Datepicker decades-view bug fix and do not introduce unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DatePicker Decade view is bugged

1 participant