Allow dismissing tooltips and popovers with the Escape key#42472
Open
mdo wants to merge 2 commits into
Open
Conversation
Contributor
Tested those with Firefox 151, Edge 148 and Safari 26.5 and all worked well with no issues. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #39692.
What
Tooltips (and popovers, which extend them) can now be dismissed by pressing the Escape key while shown, helping satisfy WCAG 1.4.13 “Content on Hover or Focus”, which requires hover/focus content to be dismissible.
The behavior matches the Menu/dropdown component's existing Escape handling, including inside a dialog: the first Escape closes the tooltip, and a subsequent Escape closes the dialog.
How
While a tooltip is shown, a
keydownlistener is attached ondocumentin the capture phase. On Escape it callspreventDefault()+stopPropagation()and thenhide()— the same approach asmenu.js'sdataApiKeydownHandler.hover-triggered tooltips (where keyboard focus isn't on the trigger. only uses the capture phase for delegated listeners, so the listener is attached natively.Verification
Beyond the unit tests, I verified in a real browser (Chrome) that a tooltip inside a **native modal ** () behaves correctly:
This is identical to how the Menu component already behaves in the same scenario.
Notes
🤖 Generated with Claude Code
EOF
)