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

Keyboard broken when minDate setted but maxDate null (opposite not tested)

Open Nico924 opened this issue 8 years ago • 8 comments

It took me some time to figure that out but when you set the minDate to something but the maxDate to null you get an "Cannot read property 'clone' of null" error, which is I guess the coning of the maxDate property. I fixed that by using a maxDate far in the future but I guess it should be addressed.

Nico924 avatar Sep 19 '17 10:09 Nico924

Actually, setting minDate or maxDate to null breaks keyboard navigation. The documentation marks these props as object, but I guess null should be ok too! So, the only solution is to not set these props at all, which is really unpractical.

EDIT What works is passing an undefined variable instead of null (which is not pretty...).

mcorteel avatar Jun 04 '18 08:06 mcorteel

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 30 '19 15:08 stale[bot]

2 years and the problem still persists

kremda avatar Oct 15 '20 14:10 kremda

Just run into this in our project - minimal test case:

import { useState } from "react";
import Datepicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";

export default function App() {
  const [date, setDate] = useState(new Date());

  return <Datepicker selected={date} onChange={setDate} maxDate={null} />;
  // return <Datepicker selected={date} onChange={setDate} />;
}

First return - keyboard navigation is broken. Second one - keyboard works correctly.

The reason for this is, as far as I could see, the following:

  • Keyboard events, including navigation, are handled in onDayKeyDown. This includes call to this.setPreSelection(newSelection) on line 764.
  • In setPreSelection, if minDate !== undefined or maxDate !== undefined, they are passed (directly or indirectly) to startOfDay. Note that this doesn't exclude nulls.
  • startOfDay, when passed null, returns Invalid Date.
  • Then, any comparison functions with Invalid Date as input, unconditionally return false.
  • Therefore, the date is considered to be out-of-bounds, and the preselection doesn't happen.

I hope that this is enough info to make a correct fix, either in code or in documentation. Since this issue is closed, ping @martijnrusschen, so that it isn't lost for now.

Cerber-Ursi avatar Mar 06 '22 17:03 Cerber-Ursi

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 02 '22 06:11 stale[bot]

Just to understand - is the "won't fix" the conscious decision, or did this issue simply get lost?

Cerber-Ursi avatar Nov 03 '22 11:11 Cerber-Ursi

Still the problem exists in 2023.

talatkuyuk avatar Jan 12 '23 14:01 talatkuyuk

Fixed by #4848, it seems?

Cerber-Ursi avatar Jul 09 '24 10:07 Cerber-Ursi

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.

github-actions[bot] avatar Jan 06 '25 02:01 github-actions[bot]

This issue was closed because it has been stalled for 10 days with no activity.

github-actions[bot] avatar Jan 17 '25 01:01 github-actions[bot]