Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pressable with button role does not fire onPress on space key press #2560

Closed
1 task done
zoontek opened this issue Jul 17, 2023 · 4 comments · Fixed by #2563
Closed
1 task done

Pressable with button role does not fire onPress on space key press #2560

zoontek opened this issue Jul 17, 2023 · 4 comments · Fixed by #2563
Labels

Comments

@zoontek
Copy link
Contributor

zoontek commented Jul 17, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Describe the issue

Hi! 👋

We noticed something strange lately: when using keyboard navigation with Pressable using role="button", using the space bar to press only trigger the visual focus (pressed is true in style), but doesn't fire onPress. When using the enter key, both are working.

Expected behavior

onPress should be fire, in a similar way as pressing the enter key

Steps to reproduce

  • Focus on a Pressable with a button role using keyboard navigation
  • Use the space key to press: visually it's pressed, but onPress is not fired

Test case

https://codesandbox.io/p/sandbox/holy-darkness-pfk6m8?file=%2Fsrc%2Fmain.tsx%3A17%2C29

Additional comments

I think it might happen since it's now using the HTML button element underneath.

@zoontek zoontek added the bug label Jul 17, 2023
@zoontek zoontek changed the title Pressable with button role does not fire onPress Pressable with button role does not fire onPress on space key press Jul 17, 2023
@necolas
Copy link
Owner

necolas commented Jul 17, 2023

This seems to be how Pressable has worked for a while. I tested 0.17 and 0.18 and it behaved the same. https://codesandbox.io/s/dazzling-greider-y38h47?file=/package.json

I couldn't change package versions in your non-standard test case.

@zoontek
Copy link
Contributor Author

zoontek commented Jul 18, 2023

For the test case, that's the new VM in codesandbox, to switch package versions you can update them in package.json and run yarn in the terminal, it truly works like locally.

Back to the issue, I made two separate playground so it's easier to identify it:

With RNW 0.17

Playground: https://codesandbox.io/s/admiring-elion-lgy9zw?file=/src/App.js

with accessibilityRole="button" (role wasn't supported at this time)

  • On space: pressed style applied ✅ + onPress fired ✅
  • On enter: pressed style applied ✅ + onPress fired ✅

without accessibilityRole="button"

  • On space: pressed style not applied ❌ + onPress not fired ❌
  • On enter: pressed style applied ✅ + onPress fired ✅

With RNW 0.19

Playground: https://codesandbox.io/s/optimistic-hypatia-3mdyyq?file=/src/App.js

with role="button"

  • On space: pressed style applied ✅ + onPress not fired ❌ <- this is the broken case
  • On enter: pressed style applied ✅ + onPress fired ✅

without role="button"

  • On space: pressed style not applied ❌ + onPress not fired ❌
  • On enter: pressed style applied ✅ + onPress fired ✅

EDIT: I tried with RNW 0.18, which behave like RNW 0.17: https://codesandbox.io/s/strange-maria-lz83d2?file=/src/App.js

@necolas
Copy link
Owner

necolas commented Jul 19, 2023

I think this will fix the issue: #2563
Let me know

@zoontek
Copy link
Contributor Author

zoontek commented Jul 20, 2023

@necolas I confirm, it fixes it. Both space and enter fire onPress + apply pressed style now

Screen.Recording.2023-07-20.at.10.39.36.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants