Skip to content

[fix] Pressable: press on Space for checkbox, radio, switch and tab roles - #2992

Merged
zoontek merged 2 commits into
necolas:masterfrom
miniware9:space-press-roles
Dec 3, 2026
Merged

zoontek merged 2 commits into
necolas:masterfrom
miniware9:space-press-roles

Conversation

@miniware9

Copy link
Copy Markdown
Contributor

Fixes #2991

Pressable takes Space only as a button: isValidKeyPress accepts it when the target is a <button> or has role="button". With role="checkbox", "radio", "switch" or "tab", Space calls no onPress, and since nothing calls preventDefault, 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 button in one set, SPACE_ACTIVATED_ROLES, which both isValidKeyPress and the preventDefault in onKeyDown read. Any other role, such as link, still takes Enter alone.

The menu pattern makes Space optional for menu items, so they stay out. menuitem was in the old preventDefault check, but that check ran only after isValidKeyPress had accepted the key, which it never did for a menuitem that isn't a <button>, so leaving it out of the set changes nothing.

Tests

  • Space presses a Pressable with each of the four roles once and calls preventDefault.
  • Space doesn't press one with role="link".

npm run test passes. Without the change to PressResponder.ts, the four role tests fail and the link one 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:

Role Space before Space after
button presses, no scroll presses, no scroll
checkbox no press, page scrolls 525 px presses once, no scroll
radio no press, page scrolls 525 px presses once, no scroll
switch no press, page scrolls 525 px presses once, no scroll
tab no press, page scrolls 525 px presses once, no scroll

Enter pressed every control once, before and after.

@zoontek
zoontek merged commit 8ca9652 into necolas:master Dec 3, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pressable: Space doesn't press a checkbox, radio, switch or tab role, and scrolls the page

2 participants