-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DateRangeCalendar] Support arrow navigation with multiple months rendered #16363
[DateRangeCalendar] Support arrow navigation with multiple months rendered #16363
Conversation
Deploy preview: https://deploy-preview-16363--material-ui-x.netlify.app/ |
143a0af
to
4148130
Compare
6f50b7e
to
e1bc77b
Compare
e1bc77b
to
a0a095c
Compare
722e8f6
to
734a9e2
Compare
952977a
to
66ed9f7
Compare
@@ -183,8 +183,8 @@ const PickersCalendarHeader = React.forwardRef(function PickersCalendarHeader( | |||
className: classes.switchViewIcon, | |||
}); | |||
|
|||
const selectNextMonth = () => onMonthChange(utils.addMonths(month, 1), 'left'); | |||
const selectPreviousMonth = () => onMonthChange(utils.addMonths(month, -1), 'right'); | |||
const selectNextMonth = () => onMonthChange(utils.addMonths(month, 1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think I should count that as a breaking change?
Strictly speaking people can keep passing the param, it's just not used anymore and instead inferred by comparing the old and new month.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure there is a need for a BC if it will not break anything on user land. 🤔
66ed9f7
to
1c62890
Compare
72e04ef
to
0aa118e
Compare
fireEvent.click(screen.getByRole('gridcell', { name: '2' })); | ||
expect(RenderCount.callCount - renderCountBeforeChange).to.equal(4); // 2 render * 2 days | ||
// 2 render (one to update tabIndex + autoFocus, one to update selection) * 2 days * 2 (because dev mode) | ||
expect(RenderCount.callCount - renderCountBeforeChange).to.equal(8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no additional render caused by this PR.
On master, we don't focus in the test and we only have 4 renders, but it's not a realistic scenario, clicking always focused and with focus with have 8 render before and after the changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
Nice improvement and cleanup! 💙 💯
Here are some strange inconsistencies I noticed, but they can be left for separate issue as the behavior is currently like that as well. 🙈
- The Focus on Date Range Calendar jumps to the day after navigating months, while on the regular Date Calendar the focus is not moved to the day.
I feel like the latter behavior is more correct. 🤔
P.S. For some reason the focus animation is stuck on the next button after navigation, while it is cleared on the previous button... 🤷
Screen.Recording.2025-01-31.at.15.46.41.mov
@@ -183,8 +183,8 @@ const PickersCalendarHeader = React.forwardRef(function PickersCalendarHeader( | |||
className: classes.switchViewIcon, | |||
}); | |||
|
|||
const selectNextMonth = () => onMonthChange(utils.addMonths(month, 1), 'left'); | |||
const selectPreviousMonth = () => onMonthChange(utils.addMonths(month, -1), 'right'); | |||
const selectNextMonth = () => onMonthChange(utils.addMonths(month, 1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure there is a need for a BC if it will not break anything on user land. 🤔
fireEvent.click(screen.getByRole('gridcell', { name: '2' })); | ||
expect(RenderCount.callCount - renderCountBeforeChange).to.equal(4); // 2 render * 2 days | ||
// 2 render (one to update tabIndex + autoFocus, one to update selection) * 2 days * 2 (because dev mode) | ||
expect(RenderCount.callCount - renderCountBeforeChange).to.equal(8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. 👍
I fixed it 👍 |
Extracted from #16175
In this PR
autoFocus
Not in this PR
Work
DayCalendar
component to theuseCalendarState
hook to be able to support multi month navigation.DayCalendar
cannot be used as standalone so there is no problem doing that.changeMonth
,changeFocusedDay
andhandleMonthChange
method into a singlesetVisibleDate
method that updates the focused day, and the current month if it changes.