react-datepicker icon indicating copy to clipboard operation
react-datepicker copied to clipboard

Unable to select minDate using keyboard

Open Svish opened this issue 6 years ago • 3 comments

Describe the bug When using a minDate of e.g. new Date(), I'm not able to select the minDate using the keyboard. The minDate is styled as not disabled, and I can select it using the mouse, but using the keyboard I'm unable to navigate to it.

I am able to navigate to it if I instead set minDate to new Date().setHours(0,0,0,0). So there seems to be some sort of mismatch in how days are disabled (styling and click-handler) and how keyboard selection is "disabled" (what days you're allowed to navigate to via keyboard).

I.e. the disabling-mechanism seems to ignore time, while the "allowed keyboard navigation"-mechanism does not. So, the fix here should probably be to also ignore time in the keyboard navigation? 🤔

To Reproduce

  1. Go to Inline version
  2. Add a minDate of new Date():
() => {
  const [startDate, setStartDate] = useState(new Date());
  return (
    <DatePicker
      selected={startDate}
      onChange={date => setStartDate(date)}
      minDate={new Date()}
      inline
    />
  );
};
  1. Using the keyboard, try navigating to the minDate.

Expected behavior I expect both the disabled styling, selecting with mouse, and selecting with keyboard, to all allow me to select the minDate.

Screenshots

image

In the screenshot the keyboard selection is on the 6th, and I'm not able to arrow-left to the 5th, even though it shows as not disabled and I can select it using the mouse.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Chrome
  • Version: 85

Svish avatar Oct 05 '20 14:10 Svish

There seems to be a similar "inaccuracy" with the month picker, where if you set minDate, it takes day (and time?) into account. Maybe this is "by design" though... there is at least no difference between mouse and keyboard selection here.

Either way, to allow selecting the minDate month, it seems to you have to set the date to 1 (and hours to 0?).

() => {
  const [startDate, setStartDate] = useState(new Date());

  const minDate = new Date();
  minDate.setHours(0,0,0,0);
  minDate.setDate(1);

  return (
    <DatePicker
      selected={startDate}
      onChange={date => setStartDate(date)}
      dateFormat="MM/yyyy"
      minDate={minDate}
      showMonthYearPicker
    />
  );
};

Svish avatar Oct 05 '20 16:10 Svish

I'm also having issues with this. @Svish I tried the last snippet you sent but the behavior you mentioned persists. And the one that it's really a blocker for me it's when I try to select the minDate with a mouse click, the minDate and the previous selected date stays highlighted.

Here with mouse click, I selected 10th and then I selected 9th, although I see that onChange was triggered and 9th was set to my state, the styles are inconsistant when selecting the minDate.

image

LuanScudeler avatar Oct 09 '20 14:10 LuanScudeler

I am working on fixing this issue

relwiwa avatar Mar 15 '21 15:03 relwiwa