gpbl / react-day-picker

DayPicker is a customizable date picker component for React. Add date pickers, calendars, and date inputs to your web applications.
https://daypicker.dev
MIT License
6.03k stars 722 forks source link

Calendar set's date to undefined when same date selected and this give inconsistent behavior! #2063

Closed Hussseinkizz closed 7 months ago

Hussseinkizz commented 7 months ago

The Problem

Apparently what the calendar provides on select is inconsistent, it can be date or undefined, and when using the format to format this given date, it raises an error as the format function can't format an undefined date. The undefined date is given if the same date is selected twice, that is if previous selected date is same as new selected date!

Expected Behavior

we can select any date any given number of times without issues provided it's not disabled!

For more context

I first opened this issue on shadcn UI repo, you can see it here and the hacky way I went over with for now, see Issue: https://github.com/shadcn-ui/ui/issues/2857

gpbl commented 7 months ago

Hi @Hussseinkizz

If I understand correctly, you are referring to the behavior that , when clicking a selected date, this becomes unselected. This is by design.

To make a date always selected, use the required prop.

https://react-day-picker.js.org/basics/selecting-days#making-a-selection-required

Hussseinkizz commented 7 months ago

Am not really sure if it's that, would that cause the value given by onselect to be undefined when same date is re-selected?