Reputation: 5663
I'm trying to build a date picker using mui/x-date-picker
where the UI opens to the year picker first. I'm also trying to limit the selectable year range with maxDate
.
Without maxDate
set, the year picker opens with the year 2023 selected by default and the year 2023 visible. With maxDate
set (e.g. to 2007) the year picker correctly limits the selectable years BUT it opens at 1900 instead of the most recent valid year.
I've searched the docs extensively but I haven't found a way to change this behavior, nor have I found a way to put the years in descending order which would also work to fix this issue.
Minimal reproducible example: https://codesandbox.io/s/mui-x-date-picker-1900-vngnhq?file=/src/App.js
Is there a way to have the year picker open at the year of the provided maxDate
? And if not, is there a way to display the years in descending order?
Upvotes: 2
Views: 936
Reputation: 822
The picker is getting the value null at the first load from the inital state, so try to pass this to avoid sending null and select the date you want as a default value:
value={value || dayjs().year(2010)}
Upvotes: 2