mui / mui-x

MUI X: Build complex and data-rich applications using a growing list of advanced React components, like the Data Grid, Date and Time Pickers, Charts, and more!
https://mui.com/x/
4.53k stars 1.32k forks source link

[DateCalendar] Calendar view reverts to wrong year when using shouldDisableDate #15428

Open ponm-dnv opened 1 day ago

ponm-dnv commented 1 day ago

Steps to reproduce

Steps:

  1. Open this link to live example: https://codesandbox.io/p/sandbox/dark-water-g2pzsw?file=%2Fsrc%2FDemo.tsx%3A19%2C39
  2. use header to select year: 2025
  3. select month: September

Current behavior

Notice that the date is not what you selected - reverts to September 2022, or the last year that you've viewed with non-disabled dates

Expected behavior

The calendar should stay on the month/year that you selected

Context

This only happens when selecting a date within a large range of disabled dates, e.g. selecting Sept 2025 when all of 2025 is disabled. Adding one non-disabled date in 2025 solves it for that year, but the problem continues for other years in the future.

Your environment

npx @mui/envinfo ``` Don't forget to mention which browser you used. Output from `npx @mui/envinfo` goes here. ```

Search keywords: shouldDisableDate, monthCalendar

LukasTy commented 1 day ago

@ponm-dnv how would you expect this scenario to work? 🤔 The whole 2025 year is disabled from shouldDisableDate, but to disable the year on YearCalendar you should use shouldDisableYear. We are not calling shouldDisableDate on month or year calendars for performance reasons, you can imagine that calling shouldDisableDate ~365 times does not sound performant. 🙈