Skip to content

fix: select the same day in range mode when range is open and min prop is 0#2816

Merged
gpbl merged 4 commits intogpbl:mainfrom
rodgobbi:issue2813-range-allow-same-day-selection
Aug 14, 2025
Merged

fix: select the same day in range mode when range is open and min prop is 0#2816
gpbl merged 4 commits intogpbl:mainfrom
rodgobbi:issue2813-range-allow-same-day-selection

Conversation

@rodgobbi
Copy link
Copy Markdown
Collaborator

@rodgobbi rodgobbi commented Aug 5, 2025

Fixes #2813

@rodgobbi rodgobbi requested a review from gpbl August 5, 2025 19:50
Copy link
Copy Markdown
Owner

@gpbl gpbl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DateRange type and adopt the date-fns DateInterval instead. I’ve added this idea to the backlog.

@gpbl gpbl merged commit f43f31e into gpbl:main Aug 14, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants