-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
[Select] Implement pointer cancellation #45789
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
base: master
Are you sure you want to change the base?
[Select] Implement pointer cancellation #45789
Conversation
cbb9faa
to
74a4a03
Compare
Netlify deploy previewhttps://deploy-preview-45789--material-ui.netlify.app/ Bundle size report
|
5d7bc9c
to
eb21c2d
Compare
eb21c2d
to
aeab281
Compare
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.
@Kartik-Murthy Thanks for the PR! Let’s keep it focused on one thing. Issues #44505 and #45374 shouldn’t be addressed yet — they’ll be handled once the Material UI Select is built on top of Base UI. For now, let’s just implement #45301. Could you remove the other changes and add a test case for #45301?
Thank you @ZeeshanTamboli for the guidance! I've revised the PR to focus solely on fixing issue #45301 . I've removed the changes related to the other issues as requested and added test cases to verify the behavior. Let me know if you'd like to see any additional changes. |
863f35e
to
7a58f33
Compare
7a58f33
to
5a7a06a
Compare
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.
Before reviewing this in detail, I’m wondering whether we should even add this feature (or maybe it's an accessibility bug?), given that it already works in Base UI Select — and Material UI will eventually be built on top of Base UI.
@aarongarciah @DiegoAndai What do you think? How far off is the Material UI release based on Base UI? How should we handle support requests and community PRs like this in the meantime? There have been a few similar feature additions — see #45789 (review).
If we decide to go ahead with adding this in 7.x
despite the upcoming Base UI integration in a new major version, I’ll proceed with a full review.
@@ -234,6 +243,11 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) { | |||
event.preventDefault(); | |||
displayRef.current.focus(); | |||
|
|||
// Mark that we've initiated a pointer interaction | |||
setIsPointerDown(true); | |||
dragSelectRef.current.startedOn = displayRef.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.
startedOn
stored here isn't used anywhere. Is it needed?
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.
Thanks for pointing this out! This line was an attempt from an earlier approach I was exploring. It's not needed for the pointer cancellation fix, so I'll remove it.
369791d
to
74f06a8
Compare
- Restore original import order as per project conventions
74f06a8
to
d91d5ba
Compare
Hey @Kartik-Murthy, thanks for working on this, sorry for the delay. @ZeeshanTamboli, we can move forward with this review. I don't have an estimate for Material UI being rebuilt on top of Base UI. About the solution, I wonder if there's a way of handling the mouse up from the items, instead of having to set a global event listener. Did you explore that idea? |
@DiegoAndai I am not sure how we can do that. We need to handle the case where the mouse is released outside the menu entirely — and that can't be reliably detected unless you're listening on |
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.
@ZeeshanTamboli thanks for the reply, that makes sense.
I made an initial review.
const handleGlobalMouseMove = () => { | ||
if (isPointerDown) { | ||
dragSelectRef.current.isDragging = true; | ||
} | ||
}; |
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.
Is it necessary to check whether the pointer is dragging? Isn't it enough to check what the mouse up event target is?
@@ -34,6 +34,54 @@ describe('<Select />', () => { | |||
skip: ['componentProp', 'componentsProp', 'themeVariants', 'themeStyleOverrides'], | |||
})); | |||
|
|||
describe('WCAG 2.5.2 - Pointer Cancellation', () => { |
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 think this is enough
describe('WCAG 2.5.2 - Pointer Cancellation', () => { | |
describe('Pointer cancellation', () => { |
while (current && !menuItem) { | ||
// Check if this element has role="option" | ||
if (current.getAttribute && current.getAttribute('role') === 'option') { | ||
menuItem = current; | ||
} | ||
current = current.parentElement; | ||
} |
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.
Why do we need this check?
current = current.parentElement; | ||
} | ||
|
||
if (!menuItem) { |
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.
If a menu item is found, should we select it? This is how native select works.
Description
This PR resolves pointer cancellation issues in the Select component to ensure compliance with WCAG 2.5.2 accessibility requirements.
Changes
Fixes #45301
Aditional