Trapping key commands in dropdown to prevent other event listeners on page from firing #1983
Replies: 2 comments 3 replies
-
Hey @PixelJanitor, Ideally the list navigation should be scoped to the list, but given your question I am thinking it is not and instead uses some kind of global keydown listener? If you have control over it, I would recommend scoping the keydown listener to the list as it then doesn't require anything special to counter the issues with global events. Here's an example: Focus the counter, and press up/down to increment it (representing the list interaction): https://codesandbox.io/p/sandbox/dropdownmenu-global-keydown-events-v99pg3 Failing that, if you can't for some reason or don't have access to that, you'll have to tangle the logic a little.
Here's an example of the latter: https://codesandbox.io/p/sandbox/dropdownmenu-local-keydown-events-forked-900w3e Hopefully that helps, let me know if I've misunderstood. ✌️ |
Beta Was this translation helpful? Give feedback.
-
I worked this around by scheduling the onSelect callback call and waiting until onSelectAutoFocus is called. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
We have a list of items in an "Inbox" type of view that have arrow up/down commands to navigate the list via addEventListeners. When a Radix dropdown or dialog is open on the same page and navigated via up/down arrows, the inbox highlights continue to work. Is there a way in the dropdown and dialog components to trap all keyboard events in them while the dropdown is open? Thanks
Beta Was this translation helpful? Give feedback.
All reactions