Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: range not selected when missing the from value #1876

Merged
merged 1 commit into from
Aug 16, 2023

Conversation

Sam-Apostel
Copy link
Contributor

Context

A user might want to filter all items before a specific date and modify the selected state outside react-day-picker.
While this works perfectly when only from is set. But when only to is set, the calendar doesn't reflect this state.
The next time a user selects a date, the state is affected like when no values were set at all.
Discussion: #1875

Analysis

selected on a range picker accepts a DateRange where from is undefined but to is a Date.
Since this works in one direction and the types allow this state, this component should reflect the other direction too.

Solution

To prevent current behaviour changes, All of the logic additions only take effect when to is set and from is not.
From within this component, this is an unreachable state, but when the state is controlled externally, it is now reflected in the internal state.

All other code changes and restructuring were made to benefit typescript.
No test were changed, few were added for specific state.

@gpbl gpbl self-requested a review August 16, 2023 09:20
@gpbl
Copy link
Owner

gpbl commented Aug 16, 2023

Ah, I knew there was a case I missed there. Thanks a lot for your PR, the tests and the fix. It doesn't happen often to get an high quality contribution!

@gpbl gpbl changed the title fix: range without 'from'-value fix: range not selected when missing the from value Aug 16, 2023
@gpbl gpbl merged commit 748dca4 into gpbl:main Aug 16, 2023
11 checks passed
@gpbl
Copy link
Owner

gpbl commented Aug 18, 2023

This fix has been released as https://github.com/gpbl/react-day-picker/releases/tag/v8.8.1. (Not sure why the release doesn't appear here)

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.

2 participants