Hacker0x01 / react-datepicker

A simple and reusable datepicker component for React
https://reactdatepicker.com/
MIT License
8.06k stars 2.24k forks source link

Keyboard Navigation to the days of a month is not working if the pre-selected date is disabled #5147

Open balajis-qb opened 2 hours ago

balajis-qb commented 2 hours ago

Describe the bug

If we select a date and disable the same date in the next or previous months, then when we navigate to the corresponding month and try using arrow keys (Tab) to navigate to the date, it won't work as there is no pre-selected date available in the month due to the fact that the corresponding date we selected previously is disabled in the corresponding month.

To Reproduce

() => {
  const [startDate, setStartDate] = useState(new Date("2024-06-01"));
  return (
    <DatePicker
      selected={startDate}
      onChange={(date) => setStartDate(date)}
      excludeDates={[new Date("2024-07-01")]}
    />
  );
};

In the above example, I programmatically selected 1st June, 2024 and disabled 1st July, 2024 (same day in the next month). Here once we navigate to July Month using the next month arrow keys, we can't able to switch the focus back any days of the month.

Expected behavior It should pre-select the first enabled date in a month in case of the previously selected date is disabled in the corresponding month.

balajis-qb commented 2 hours ago

Hi @martijnrusschen, Please assign this issue to me