fix: range not selected when missing the from
value
#1876
Merged
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.
Context
A user might want to filter all items before a specific date and modify the
selected
state outsidereact-day-picker
.While this works perfectly when only
from
is set. But when onlyto
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 wherefrom
is undefined butto
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 andfrom
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.