-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix modal escape key propagation #17297
Conversation
} | ||
|
||
/** | ||
* Stops proagation of the escape key outside the context of the modal. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix typo and describe that it triggers the onRequestClose
prop.
Noting that I have a similar issue in #16964. |
8853deb
to
64ef592
Compare
64ef592
to
d10fa38
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This worked great with the previous commit when I was testing earlier today. Code looks great with all refactorings applied and it solved the issue I had with the PR I linked in my previous comment.
I'll try to retest this PR later today. I had some very minor question which isn't a blocker.
Re-tested again. I can confirm it all works as advertised. Excellent job @talldan 🎉 |
Description
Modal
components handle anescape
key down as a global event. Unfortunately this means that the modal cannot stop propagation of an event to the outer context. It can only cancel bubbling to an inner context.With our current implementation of modals, this hasn't really been an issue. On #17265 I'm implementing a modal that's launched from a block toolbar, and pressing
esc
to close the modal is triggering navigation mode.This change in this PR is to stop using a global event and instead use an event on the
IsolatedEventContainer
component. This matches how thePopover
component is implemented:gutenberg/packages/components/src/popover/index.js
Lines 390 to 399 in f198997
gutenberg/packages/components/src/popover/index.js
Lines 299 to 311 in f198997
This PR also moves the
IsolatedEventContainer
component intoModalFrame
. This component is responsible for rendering the overlay behind the modal. Nesting it insidewithFocusReturn
ensures that when the overlay is clicked, focus is returned to the element that opened the modal.How has this been tested?
Test that modals:
Screenshots
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist: