Skip to content

Allow dismissing tooltips and popovers with the Escape key#42472

Open
mdo wants to merge 2 commits into
v6-devfrom
mdo/issue-39692
Open

Allow dismissing tooltips and popovers with the Escape key#42472
mdo wants to merge 2 commits into
v6-devfrom
mdo/issue-39692

Conversation

@mdo
Copy link
Copy Markdown
Member

@mdo mdo commented Jun 5, 2026

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 keydown listener is attached on document in the capture phase. On Escape it calls preventDefault() + stopPropagation() and then hide() — the same approach as menu.js's dataApiKeydownHandler.

  • Capture phase + document scope is required so the tooltip handler runs before the dialog's own handler, and so it works for 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.
  • The handler is guarded on , and the listener is removed in and .

Verification

Beyond the unit tests, I verified in a real browser (Chrome) that a tooltip inside a **native modal ** () behaves correctly:

  • 1st Escape → tooltip hides, dialog stays open (the native is suppressed)
  • 2nd Escape → dialog closes

This is identical to how the Menu component already behaves in the same scenario.

Notes

  • No changes are included; those are regenerated separately on this branch.
  • Docs updated for both tooltips and popovers.

🤖 Generated with Claude Code
EOF
)

@mdo mdo requested a review from a team as a code owner June 5, 2026 06:13
@coliff
Copy link
Copy Markdown
Contributor

coliff commented Jun 5, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants