Skip to content

fix(datepicker): allow selecting a day that is only partly inside the min/max range - #333

Open
Mohith26 wants to merge 1 commit into
frontapp:mainfrom
Mohith26:fix/datepicker-partial-day-selection
Open

Mohith26 wants to merge 1 commit into
frontapp:mainfrom
Mohith26:fix/datepicker-partial-day-selection

Conversation

@Mohith26

@Mohith26 Mohith26 commented Nov 3, 2026

Copy link
Copy Markdown

The calendar marks a day as selectable when any part of it is inside the range (minDate <= day.endOf('day'), maxDate >= day.startOf('day')), but onDateSelect merges the clicked day with the current selection's time (or midnight when nothing is selected) and silently drops the click if that exact moment is out of range.

The most common way to hit this is minDate={new Date()} with no value: today is shown as selectable, but clicking it builds today at 00:00, which is before minDate, so nothing happens. The same thing happens with a selected time earlier than minDate's time on the first day, or later than maxDate's time on the last day.

This change clamps the merged time to minDate / maxDate when it falls on the same day as the bound, so a click on a day the calendar shows as selectable always selects it. Days entirely outside the range are still ignored, and times already inside the range are unchanged.

Testing: added __tests__/datepicker.spec.tsx (4 cases). The two clamping cases fail on main (the click is ignored and onChange gets the old value) and pass with the fix; the in-range and fully-out-of-range cases pass on both. yarn test (72 passed), yarn lint on the touched files, yarn typecheck and prettier --check pass locally.

I used AI assistance while working on this and reviewed and tested the change myself.

… min/max range

The calendar shows a day as selectable when any part of it is inside
[minDate, maxDate], but the click merges the day with the current time (or
midnight) and drops the selection if that moment is out of range. With
minDate set to now, today looks selectable but clicking it does nothing.
Clamp the merged time to minDate/maxDate when it falls on the same day.

This branch has not been deployed

No deployments
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.

1 participant