-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Bug]: Escape key doesn't close dialogs after a mouse click inside it #524
Comments
Same issue is happening with a Vue version. |
I'm not sure if this is the optimal solution, but as a workaround I've added a global event listener to the window...
|
A possible (working) solution would be adding
|
My issue is similar, ESC key wont work anywhere unless I implement @kieranm solution, then
|
I am still 1 month later can not understand the solution to this issue, do i need to fork the repo and add the props to dialog....? |
We've "fixed" an issue when we had nested Dialogs ([#430](#430)). The `escape` would not close the correct Dialog. The issue here was with the logic to know whether we were the last Dialog or not. The issue was _not_ how we implemented the `close` functionality. To make things easier, we moved the global window event to a scoped div (the Dialog itself). While that fixed the nested Dialog issue, it introduced this bug where `escape` would not close if you click on a non-focusable element like a span in the Dialog. Since that PR we did a bunch of improvements on how the underlying "stacking" system worked. This PR reverts to the "global" window event listener so that we can still catch all of the `escape` keydown events. Fixes: #524 Fixes: #693
* fix broken `escape` key behaviour We've "fixed" an issue when we had nested Dialogs ([#430](#430)). The `escape` would not close the correct Dialog. The issue here was with the logic to know whether we were the last Dialog or not. The issue was _not_ how we implemented the `close` functionality. To make things easier, we moved the global window event to a scoped div (the Dialog itself). While that fixed the nested Dialog issue, it introduced this bug where `escape` would not close if you click on a non-focusable element like a span in the Dialog. Since that PR we did a bunch of improvements on how the underlying "stacking" system worked. This PR reverts to the "global" window event listener so that we can still catch all of the `escape` keydown events. Fixes: #524 Fixes: #693 * update changelog
Hey! Thank you for your bug report! This should be fixed, and will be available in the next release. You can already try it using:
|
What package within Headless UI are you using?
@headlessui/react
What version of that package are you using?
v1.2.0
What browser are you using?
Chrome
Reproduction repository
https://headlessui.dev/react/dialog
Describe your issue
Setup
Expected behaviour:
The dialog captures the escape key and closes. Even though clicking moves focus off child elements, the dialog is still open and I think users would reasonably still expect to be able to close it with the keyboard.
Actual behaviour:
The dialog doesn't capture the escape key and doesn't close.
This issue is reproducible using the example on the Headless UI site so I haven't created a codesandbox specifically for it, but please let me know if one is required.
Apologies if I'm missing some important context!
Thanks!
The text was updated successfully, but these errors were encountered: