Skip to content

[fix] Pressable: call onPress on Enter when role is "link" - #2926

Merged
zoontek merged 2 commits into
necolas:masterfrom
Enesuygurs:fix/pressable-link-enter-key
Nov 5, 2026
Merged

zoontek merged 2 commits into
necolas:masterfrom
Enesuygurs:fix/pressable-link-enter-key

Conversation

@Enesuygurs

Copy link
Copy Markdown
Contributor

Fixes #2681.

<Pressable role="link" onPress={...} /> renders a div with role="link". Pressing Enter on it fires onPressIn / onPressOut, but never onPress.

The keyup handler in PressResponder skips onPress for native interactive elements, because the browser dispatches a click for them. That list also included role === 'link', but an ARIA role does not give a div that native behavior, so onPress was never called. A real anchor (Pressable with href) is still covered by the a element check, so it doesn't fire twice.

Test plan

  • Pressable with role="link" calls onPress once on Enter (fails before the fix)
  • Pressable with role="link" and href renders an <a> and leaves activation to the native click
  • npm run unit: 48 suites, 703 passed, 6 skipped
  • npm run lint, prettier --check

An ARIA "link" role does not make an element dispatch a native 'click' on
Enter, so PressResponder must call onPress itself unless the element is an
actual anchor.

Fix necolas#2681
@zoontek
zoontek force-pushed the fix/pressable-link-enter-key branch from 0724544 to b018fc5 Compare November 5, 2026 15:40
@zoontek
zoontek merged commit 3e165cf into necolas:master Nov 5, 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's onPress method is not triggered by "enter" key when role="link"

2 participants