🐛 Fix: Respect minDate/maxDate in Month Dropdown (showMonthDropdown)#6306
Open
balajis-qb wants to merge 1 commit into
Open
🐛 Fix: Respect minDate/maxDate in Month Dropdown (showMonthDropdown)#6306balajis-qb wants to merge 1 commit into
showMonthDropdown)#6306balajis-qb wants to merge 1 commit into
Conversation
d6d0dab to
0616f6d
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6306 +/- ##
==========================================
+ Coverage 99.29% 99.32% +0.02%
==========================================
Files 30 30
Lines 3822 3831 +9
Branches 1648 1669 +21
==========================================
+ Hits 3795 3805 +10
+ Misses 26 25 -1
Partials 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
0616f6d to
3664230
Compare
…ing minDate/maxDate showMonthDropdown rendered all 12 months unconditionally, letting users navigate outside minDate/maxDate even though showMonthYearDropdown already respected the range. Reuse isMonthDisabled (same helper used by the full month-grid picker) to gray out out-of-range months in both scroll and select modes, rather than filtering them out, since the displayed year is controlled externally and filtering would make the option list's length/positions shift depending on which year is in view. Fixes Hacker0x01#6286
3664230 to
e1ff9e1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Linked issue: #6286
Problem
showMonthDropdownignoredminDate,maxDate,excludeDates,includeDates, andfilterDate, allowing navigation to any month of the year even when the date range restricted it. For example, withminDate=2025-01-01andmaxDate=2025-06-30, users could still pick July–December 2025 via the month dropdown.showMonthYearDropdownalready handled this correctly, becauseMonthYearDropdownbuilds its option list directly from theminDate–maxDaterange.MonthDropdownis a separate, independent component that always rendered all 12 months and calledonChangeunconditionally — it never consultedminDate/maxDateat all.Fix
Reused the existing
isMonthDisabledhelper (already used by the full month-grid picker inmonth.tsxfor the identical constraint) to disable out-of-range months in both dropdown modes:month_dropdown_options.tsx(scroll mode) — each month option is checked againstminDate/maxDate/excludeDates/includeDates/filterDate. Disabled options get an--disabledclass +aria-disabled, and clicks/Enter on them are ignored.month_dropdown.tsx(select mode) — the corresponding<option>elements get the nativedisabledattribute;onChangealso guards against disabled months.calendar.tsx— passes the currently vieweddateintoMonthDropdownso it has year context (needed becauseMonthDropdownonly tracks a bare month index 0–11, not a year).datepicker.scss— added a muted/cursor: defaultstyle for.react-datepicker__month-option--disabled, matching the existing disabled-day styling.Why gray out instead of filter out?
YearDropdownandMonthYearDropdownfilter their option lists because each option is a self-contained unit (a year, or a year+month pair) — whether it's in range depends only onminDate/maxDate.MonthDropdownis different: its 12 options ("January"–"December") only make sense relative to whichever year is currently displayed, and that year is controlled externally (the siblingYearDropdown, or prev/next navigation) —MonthDropdownhas no say in it. If we filtered instead of disabled, the list's length and item positions would change every time the user changed the year. For example, withminDate=Jun 2024andmaxDate=Mar 2026: viewing 2024 would show 6 months, viewing 2025 would show all 12, and viewing 2026 would show 3 — a jarring, unstable list for what's meant to be a fixed 12-month picker.This is exactly the same constraint the full month-grid picker (
month.tsx, used byshowFullMonthYearPicker) already faces, and it solves it by disabling rather than filtering (isMonthDisabled/month-text--disabled). Graying out keeps the option list stable and consistent with that existing precedent, and is also more accessible —aria-disabledtells assistive tech the option exists but isn't currently selectable, rather than having it silently disappear.Contribution checklist