Closed narehart closed 1 year ago
The funny thing - it's working that way only for Enter
, not for Space
.
Maybe that's because of the way React handles onClick
handlers. They are also triggered by the Enter
key. My guess is this uses the keyup
event under the hood. So I think what's happening here is the onKeyDown
opens FocusOn
which moves focus to the button
and then when the key is released the onClick
or onKeyUp
event is fired which both use keyup
.
If I defer rendering of the onFocus
to the end of the event loop it doesn't trigger the onClick
handler: https://codesandbox.io/s/divine-flower-jq4rn
Let me create issue for React then. It shall not be solved here.
This issue has been marked as "stale" because there has been no activity for 2 months. If you have any new information or would like to continue the discussion, please feel free to do so. If this issue got buried among other tasks, maybe this message will reignite the conversation. Otherwise, this issue will be closed in 7 days. Thank you for your contributions so far.
If an
onKeyDown
handler causesFocusOn
to render and the first focusable element has anonKeyUp
oronClick
handler, that handler will also be called.Reproduced here: https://codesandbox.io/s/wizardly-vaughan-2y8in Doesn't happen when focusing using refs: https://codesandbox.io/s/naughty-curie-kmmu8