Repository navigation
[fix] Pressable: press on Space for checkbox, radio, switch and tab roles - #2992
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2991
Pressabletakes Space only as a button:isValidKeyPressaccepts it when the target is a<button>or hasrole="button". Withrole="checkbox","radio","switch"or"tab", Space calls noonPress, and since nothing callspreventDefault, the browser scrolls the page instead. The WAI-ARIA Authoring Practices have Space toggle a checkbox and a switch, check a radio button and activate a tab.This puts those four roles beside
buttonin one set,SPACE_ACTIVATED_ROLES, which bothisValidKeyPressand thepreventDefaultinonKeyDownread. Any other role, such aslink, still takes Enter alone.The menu pattern makes Space optional for menu items, so they stay out.
menuitemwas in the oldpreventDefaultcheck, but that check ran only afterisValidKeyPresshad accepted the key, which it never did for amenuitemthat isn't a<button>, so leaving it out of the set changes nothing.Tests
Pressablewith each of the four roles once and callspreventDefault.role="link".npm run testpasses. Without the change toPressResponder.ts, the four role tests fail and thelinkone passes.Test plan
In the reproduction linked from #2991, a blank Expo SDK 58 app on react-native-web 0.21.4, in Chrome 157 on Linux, I focused each control and pressed Space, then Enter, before and after applying this change to the installed package:
buttoncheckboxradioswitchtabEnter pressed every control once, before and after.