Hacker0x01 / react-datepicker

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

The Today Button is not accessible via Tab key for keyboard users #3885

Open talatkuyuk opened 1 year ago

talatkuyuk commented 1 year ago

The problem is: The keyboard users can not focus to the Today Button (actually it is a div) via Tab key.

Today button's tab index (tabIndex) actually should be set to 0. Otherwise it is not accessible from keyboard.

https://github.com/Hacker0x01/react-datepicker/blob/master/src/calendar.jsx#L734

marwanKettleCom commented 1 year ago

Yes having the same issue. Please fix. Thank you!

LGLabGreg commented 1 year ago

There is no need to add a button as there is already logic to set tabindex, but currently it is possible that no date has tabindex=0 if the datepicker loads with no selected date.

https://github.com/Hacker0x01/react-datepicker/blob/master/src/day.jsx#L282

So if not keyboardSelected/selected/preselected it should default to today or first day of the month.

LGLabGreg commented 1 year ago

Here's a solution

const datePickerRef = useRef(null);

useEffect(() => {
  if (datePickerRef.current) {
    datePickerRef.current.setPreSelection(new Date());
  }
}, [datePickerRef]);

<DatePicker ref={datePickerRef} />
github-actions[bot] commented 4 months ago

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 10 days.