-
Notifications
You must be signed in to change notification settings - Fork 12
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
Capture escape key in combobox and listbox so it doesn't close form #2557
Comments
This is not easy! It seems like the combobox should be preventing the Esc from bubbling up (headless source), but as far as I can tell, the combobox is not even seeing the event, which suggests the side modal form dialog is getting it first and eating it. |
Ok, I was able to figure this out thanks to Chrome's UI for looking at all event listeners relevant to an element: The reason the modal dialog is getting the event first is that Radix's Claude 3.5 Sonnet explaining propagation phases
React's event delegation can sometimes make the actual order less obvious because all events are attached to the root, but the synthetic event system simulates natural DOM propagation. This was added in radix-ui/primitives#2761 in response to radix-ui/primitives#2653. This is hooked up as follows: Radix onKeyDown={(e) => {
console.log('modal content keydown', e)
}}
onEscapeKeyDown={(e) => {
console.log('modal content esc keydown', e)
if (e.target instanceof HTMLInputElement) {
console.log({ open: e.target.dataset.open !== undefined })
// e.preventDefault()
}
}} We can detect that the escape keypress comes from a relevant input, but it all feels rather backwards. More importantly, calling |
Pressing escape in a combobox to close the popover currently gets you out of the entire form. #2328 or similar would block the form from closing, which is an improvement, but really we shouldn't even see that popup if we're just pressing escape to close a popover. So let's consider this a separate issue from #2186.
The text was updated successfully, but these errors were encountered: