Skip to content

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

Open
Enesuygurs wants to merge 1 commit into
necolas:masterfrom
Enesuygurs:fix/pressable-link-enter-key
Open

Enesuygurs wants to merge 1 commit into
necolas:masterfrom
Enesuygurs:fix/pressable-link-enter-key

Conversation

@Enesuygurs

Copy link
Copy Markdown

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

This branch has not been deployed

No deployments
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"

1 participant