-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[RAC] Checkbox should not be toggled with 'Enter' key #6398
Comments
Your analysis looks correct. I'm also not too sure about the fix for it, but this seems like a reasonable starting place. Thank you for the very detailed issue! |
I've looked into this a little more and realized the way RAC Checkbox's To be more specific, it looks like So because of this duality of the roles of Specifically in these functions: react-spectrum/packages/@react-aria/interactions/src/usePress.ts Lines 767 to 781 in d80999e
react-spectrum/packages/@react-aria/interactions/src/usePress.ts Lines 876 to 890 in d80999e
react-spectrum/packages/@react-aria/interactions/src/usePress.ts Lines 904 to 909 in d80999e
Lastly, I think we shouldn't pass |
Provide a general summary of the issue here
Based on the code below and https://www.w3.org/WAI/ARIA/apg/patterns/checkbox/#keyboardinteraction, it should be the case that 'Enter' key shouldn't invoke Checkbox toggling:
react-spectrum/packages/@react-aria/interactions/src/usePress.ts
Lines 904 to 909 in b294de8
But actually it does:
Screen.Recording.2024-05-17.at.12.30.39.AM.mov
React Spectrum Checkbox, on the other hand, doesn't suffer from this issue as shown in the video above.
I did some digging and found out the
element
below when thekey
is'Enter'
could actually beHTMLLabelElement
in addition toHTMLInputElement
, rendering the second condition in the return expression (three lines starting with!
)true
when it'sHTMLLabelElement
and hence recognized as a valid key:react-spectrum/packages/@react-aria/interactions/src/usePress.ts
Lines 767 to 781 in d80999e
On the other hand, when
'Space'
is pressed, it looks like theelement
above only evaluates toHTMLInputElement
, which is desirable.I think this is due to the double usage of
usePress()
inuseToggle()
below:react-spectrum/packages/@react-aria/toggle/src/useToggle.ts
Lines 66 to 77 in d80999e
where one
pressProps
is fed intolabelProps
and the other intoinputProps
.🤔 Expected Behavior?
Checkbox should not be toggled with 'Enter' key
😯 Current Behavior
Checkbox can be toggled with 'Enter' key
💁 Possible Solution
The diff above would fix it, but I'm not sure it's the best way to go about it.
🔦 Context
No response
🖥️ Steps to Reproduce
RAC Checkbox (can be toggled on/off with Enter key)
https://react-spectrum.adobe.com/react-aria/Checkbox.html#example
React Spectrum Checkbox (cannot be toggled on/off with Enter key)
https://react-spectrum.adobe.com/react-spectrum/Checkbox.html#example
Version
1.2.0
What browsers are you seeing the problem on?
Chrome
If other, please specify.
No response
What operating system are you using?
macOS Sonoma 14.4.1
🧢 Your Company/Team
No response
🕷 Tracking Issue
No response
The text was updated successfully, but these errors were encountered: