-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[pickers] Add PageUp
and PageDown
support for time components
#14812
[pickers] Add PageUp
and PageDown
support for time components
#14812
Conversation
Deploy preview: https://deploy-preview-14812--material-ui-x.netlify.app/ |
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 to see the accessibility improving here
Thanks for synchronizing with the core team 👍
PageUp
and PageDown
support for TimeClock
componentPageUp
and PageDown
support for TimeClock
, DigitalClock
and MultiSectionDigitalClock
components
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.
Thank you, this is a nice improvement! 👍
There could be ideas on how to improve behavior with different timeSteps
settings, but that's debatable and I'd say a question we should raise only when community demands it. 👍
packages/x-date-pickers/src/MultiSectionDigitalClock/tests/MultiSectionDigitalClock.test.tsx
Outdated
Show resolved
Hide resolved
packages/x-date-pickers/src/MultiSectionDigitalClock/MultiSectionDigitalClockSection.tsx
Outdated
Show resolved
Hide resolved
packages/x-date-pickers/src/DigitalClock/tests/DigitalClock.test.tsx
Outdated
Show resolved
Hide resolved
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.
LGTM. 👍
Leaving a final nitpick for the tests in general.
But feel free to ignore it as we'd need to add eslint ignores to allow for this.
We can keep it for when we refactor to use userEvent
. 👍
packages/x-date-pickers/src/DigitalClock/tests/DigitalClock.test.tsx
Outdated
Show resolved
Hide resolved
PageUp
and PageDown
support for TimeClock
, DigitalClock
and MultiSectionDigitalClock
componentsPageUp
and PageDown
support for time components
if (!listRef.current) { | ||
return; | ||
} |
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.
This code is impossible to reach?
if (!listRef.current) { | |
return; | |
} |
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.
In theory listRef.current
can be null, so this is meant to assure null safety on the lines below (and prevent TS complaints 😅)
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.
In theory listRef.current can be null
Only if the ref is not applied to the right element. This sounds unlikely to happen in a future refactoring, not with our test suite.
I think that using listRef.current!
so it gets transpiled to listRef.current
is much better. No extra bundle size or runtime time spent on this. If done at scale, I would hope this brings more than a +1% improvement.
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.
That was my suggestion to go the safer route and prevent cases where DOM could be tampered with.
But given most other cases, where <x>Ref.current
is accessed, we could indeed simplify to listRef.current!
.
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 will add it to this PR
Thanks for the suggestion 🙏
const children = listElement.children; | ||
return Array.from(children).findIndex((child) => child === getActiveElement(document)); |
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.
How about we simplify it down to?
const children = listElement.children; | |
return Array.from(children).findIndex((child) => child === getActiveElement(document)); | |
return Array.from(listElement.children).indexOf(getActiveElement(document)!); |
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.
Indeed IndexOf
is more performatic than findIndex
Opened this PR for it
Thanks ! 🙂
Closes #14548
To achieve it on the
DigitalClock
andMultiSectionDigitalClock
I had to manipulate the list focus on our side. This approach was discussed with Diego and Jun.