Filter datepicker selectors and disable out-of-range navigation buttons#4084
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughDatepicker tests were added and the Datepicker now forwards calculated min/max dates into DropdownCaption; DropdownCaption's prop types and navigation logic were updated to respect optional minDate/maxDate when building year/month options and enabling/disabling navigation. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/layout/Datepicker/DatepickerComponent.test.tsx`:
- Line 6: The tests import date-fns helpers (endOfYear, startOfYear) and build
local-midnight Date instances which become flaky across timezones; replace those
imports with the repository UTC helper (use the file's existing UTC-noon
fixtures or a helper like utcNoon/utcDateAtNoon) and update the three test
suites that construct local-midnight dates to instead use UTC-noon fixtures
(e.g., 'YYYY-MM-DDT12:00:00.000Z' or the existing defaultStart/defaultEnd
constants) before calling toISOString(), ensuring all date construction in the
DatepickerComponent tests uses timezone-safe UTC fixtures rather than
local-midnight Dates.
In `@src/layout/Datepicker/DropdownCaption.tsx`:
- Around line 17-22: The DropdownCaption currently uses calendarMonth.date
directly for the select values causing a mismatch when calendarMonth is outside
minDate/maxDate; update DropdownCaption to clamp the initially displayed month
by computing a clampedDate = clamp(calendarMonth.date, minDate, maxDate) (or
similar) and use that clampedDate for the initial selected year/month and any
derived values (e.g., when building years/months options and the select value).
Ensure the same clamping logic is applied where calendarMonth.date is used for
initial selection (also in the corresponding code around lines 42-48) so the
caption's selected option always matches the filtered years/months.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 52a365bc-485e-4c7d-b52e-ed919e83b371
📒 Files selected for processing (3)
src/layout/Datepicker/DatepickerComponent.test.tsxsrc/layout/Datepicker/DatepickerComponent.tsxsrc/layout/Datepicker/DropdownCaption.tsx
walldenfilippa
left a comment
There was a problem hiding this comment.
Nice done! 🥳
The Cypress test that failed looks like a flaky test. It seems that minDatePicker and maxDatePicker are sometimes not saved before Cypress checks the date button: cy.findByRole('button', { name: /tirsdag 1. juli 2025/i }).should('be.disabled');.
I suggest adding a waitUntilSaved() after setting minDatePicker and maxDatePicker in the date‑picker test. This appears to resolve the flakiness.
|
|
I added |
|
Supert, takk for at du såg på den og fikset testen, Filippa! Jeg bare merget den nå 😄 |



Description
This PR ensures that years and months outside of
minDateandmaxDateare not selectable.If the user has december 2025 selected, with
maxDatein january 2026, and switches to year 2026, the month selector automatically updates to the latest available month (january) instead of keeping the previous selection.Additionally, the previous/next month buttons are disabled when this will result in navigating beyond the configured limits.
Example below where
maxDateis set to 28th of march 2026.datepicker-updated-logic.mp4
Related Issue(s)
Verification/QA
kind/*andbackport*label to this PR for proper release notes groupingSummary by CodeRabbit
Bug Fixes
Tests