Prevent Auto Select of date when maxDate is set - Material UI React JS

Viewed 483

Currently when I set a maxDate to the DatePicker it tends to automatically selects a date. Is there a way to prevent this?

const maxDateAllowed = () => { 
  var date = new Date();
  date.setFullYear(date.getUTCFullYear() - 14);
  return date;
};

 <KeyboardDatePicker 
      variant="inline"
      value={!myDate ? null : myDate}
      maxDate={maxDateAllowed()}
      onChange={date => handleDateChange(date)}
   />
1 Answers

Just In case anyone run into the same problem.

use the property initialFocusedDate and set the value same as your maxDate

<KeyboardDatePicker 
      variant="inline"
      value={!myDate ? null : myDate}
      maxDate={maxDateAllowed()}
      initialFocusedDate={maxDateAllowed()}
      onChange={date => handleDateChange(date)}
   />
Related