necolas / react-native-web

Cross-platform React UI packages
https://necolas.github.io/react-native-web
MIT License
21.46k stars 1.77k forks source link

Pressable's onPress method is not triggered by "enter" key when role="link" #2681

Open louie-succio opened 3 weeks ago

louie-succio commented 3 weeks ago

Is there an existing issue for this?

Describe the issue

When using the Pressable component from react-native, the onPress prop does not trigger when the role="link" and the element has focus and "enter" is tapped from the keyboard. The only way currently to have "enter" trigger a Pressable with role="link" is to use onPressOut.

Expected behavior

When a Pressable has onPress and role="link" clicking and hitting "enter" on the Pressable should trigger onPress

Steps to reproduce

  1. Use <Pressable role="link" onPress={() => console.log("onPress triggered")} />
  2. Focus on pressable element using tab key
  3. Hit "enter"
  4. Notice there is no log in the console
  5. Click the pressable
  6. Notice there is a log in the console

Test case

https://codesandbox.io/p/sandbox/clever-joana-w2r4hd?file=%2Fsrc%2FApp.js

Additional comments

The reason this is coming up is because of an accessibility audit we are going through where button that act as links need to be marked up as so.

necolas commented 2 weeks ago

I'll review a PR