[Select] Inability to stop Escape keyDown propagation
See original GitHub issueBug report
If there’s a keydown handler defined above select component, there’s no way to prevent event propagation when Escape is pressed but keep closing the select as expected.
See reproducible CodeSandbox example
Current Behavior
The only way to prevent event propagation is to define
<Box onKeyDown={(e) => {
if (e.key === "Escape") {
console.log("this should not be called");
}
}}>
<Select>
...
<SelectContent
onKeyDown={(e) => {
if (e.key === "Escape") {
// propagation stopped and Box onKeyDown is not called
// but Select is not closed either
e.stopPropagation();
}
}}
/>
...
</Select>
</Box>
but it breaks “close select when Esc is pressed” fuctionality.
Expected behavior
I can prevent Box onKeyDown event from being called, but still keep closing Select when Esc is pressed.
Reproducible example
Your environment
Software | Name(s) | Version |
---|---|---|
Radix Package(s) | react-select | 0.1.1 |
React | n/a | 17.x |
Browser | Chrome |
Issue Analytics
- State:
- Created a year ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
how to prevent propagation of the same event in different ...
You have different event which are being called in both the component, I am unable to understand what causes the issue if you...
Read more >When to actually use preventDefault(), stopPropagation(), and ...
Calling preventDefault() in a 'keydown' event handler tells the browser you don't want the browser to do the default action. The browser is...
Read more >Element: keydown event - Web APIs | MDN
Unlike the deprecated keypress event, the keydown event is fired for all keys, regardless of whether they produce a character value.
Read more >Working with Events - StimulusReflex
Similar to keydown , keypress returns the previous value when you access event.target.value . However, it only fires for keys that product a...
Read more >Keyboard: keydown and keyup - The Modern JavaScript Tutorial
So, event.code may match a wrong character for unexpected layout. Same letters in different layouts may map to different physical keys, leading ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
So, I solved the problem with a generic attribute that I added to SelectContent and SelectOption components, this an event is targeted from these elements it gets skipped in a global shortcut handler.
So, the new Select is coming to Linear. We already use Tabs component and more to come. Thanks for an amazing library.
@benoitgrelard these are good ideas, thanks for sharing. I’ll explore these possibilities