Conversation
gpbl
approved these changes
Aug 10, 2025
Owner
gpbl
left a comment
There was a problem hiding this comment.
Nice, thanks!
I'm not convinced by the RangeResetSelection example: while it reproduces the bug's use case, it's not very clear.
I would have implemented the example starting with an open range:
export function OpenRange() {
const [range, setRange] = useState<DateRange | undefined>({
from: new Date(),
to: undefined,
});
let footer = `Please pick the first day.`;
if (range?.from) {
if (!range.to) {
footer = range.from.toLocaleDateString();
} else {
footer = `${range.from.toLocaleDateString()}—${range.to.toLocaleDateString()}`;
}
}
return (
<DayPicker
mode="range"
selected={range}
onSelect={setRange}
footer={footer}
/>
);
}The test description could be:
When the initial selected range is open, clicking the start of the range should close the range.
I’m also not sure the test is necessary, since it appears to be already covered by addToRange.test.ts.
I suggest either removing the example or updating it to something simpler, like the example above.
Aside:
- We’ve never explicitly used the terms “open” or “closed” range in our code, but I think they fit well.
- It might be worth investigating whether we can deprecate the
DateRangetype and adopt the date-fnsDateIntervalinstead. I’ve added this idea to the backlog.
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.
Fixes #2813