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!
I have developed a small piece of code to support multiple calendar systems (e.g. Jalali + Gregorian) for MUI Picker with a toggle button inside the calendar popover as the switch.
Everything worked as expected with one exception. When I switch from Jalali to Gregorian and vice versa, currentMonth value of calendarState does not update which leads to a minor UX bug in some situations.
The utils variable is updated on every calendar system switch, but since the currentMonth value is inside the initial value of the calendarState reducer, it doesn't update on rerenders, resulting in the aforementioned UX bug.
As an example, in Jalali calendar, Today is 29th of Mordad month (= 20th of August), and when you open the picker, you see current month correctly. (currentMonth = 1st of Mordad in Jalali & 23rd of July in Gregorian)
But when you switch to Gregorian calendar, instead of having August, you'll get July. That is because currentMonth variable is not updated and is 23rd of July.
Expected behavior 🤔
I would expect MUI codebase to anticipate changes on utils context variable, since I have developed a multi-calendar system mechanism.
Although if MUI team developed this multi-calendar system feature on subsequent releases, I would be totally grateful; My problem would be solved with just re-coding the useCalendarState file in a way changes of utils variable would impact all related sections including currentMonth.
I have solved this problem with one tiny line of code in the file above temporarily using yarn-patch, but I would be thankful if we have the consistency for this feature on next releases.
Duplicates
Latest version
Current behavior 😯
I have developed a small piece of code to support multiple calendar systems (e.g. Jalali + Gregorian) for MUI Picker with a toggle button inside the calendar popover as the switch. Everything worked as expected with one exception. When I switch from Jalali to Gregorian and vice versa,
currentMonth
value ofcalendarState
does not update which leads to a minor UX bug in some situations.As you can see in the
useCalendarState
file:The
utils
variable is updated on every calendar system switch, but since thecurrentMonth
value is inside the initial value of thecalendarState
reducer, it doesn't update on rerenders, resulting in the aforementioned UX bug.As an example, in Jalali calendar, Today is 29th of Mordad month (= 20th of August), and when you open the picker, you see current month correctly. (
currentMonth
= 1st of Mordad in Jalali & 23rd of July in Gregorian) But when you switch to Gregorian calendar, instead of having August, you'll get July. That is becausecurrentMonth
variable is not updated and is 23rd of July.Expected behavior 🤔
I would expect MUI codebase to anticipate changes on
utils
context variable, since I have developed a multi-calendar system mechanism. Although if MUI team developed this multi-calendar system feature on subsequent releases, I would be totally grateful; My problem would be solved with just re-coding theuseCalendarState
file in a way changes ofutils
variable would impact all related sections includingcurrentMonth
.I have solved this problem with one tiny line of code in the file above temporarily using yarn-patch, but I would be thankful if we have the consistency for this feature on next releases.
The line is added after
changeMonth
function definition.Steps to reproduce 🕹
Sandbox Example Link of the Bug
Context 🔦
No response
Your environment 🌎
No response
Order ID 💳 (optional)
No response