fix(VOverlay): always return focus to activator on Escape key#22755
Open
mixelburg wants to merge 4 commits intovuetifyjs:masterfrom
Open
fix(VOverlay): always return focus to activator on Escape key#22755mixelburg wants to merge 4 commits intovuetifyjs:masterfrom
mixelburg wants to merge 4 commits intovuetifyjs:masterfrom
Conversation
Previously, focus was only returned to the activator element when the active element was inside the overlay content at the time Escape was pressed. This caused focus to be lost when: - The menu was opened via click but focus was not captured into the content - The activator is not keyboard-focusable (e.g. coordinate-positioned menus) Always attempt to return focus to the activator on Escape. If the activator is not focusable (no tabIndex), the focus() call is a no-op, preserving existing behaviour for coordinate-based menus. Fixes vuetifyjs#22560
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.
Fixes #22560
Problem
Keyboard focus was lost after closing a
v-menu(or any overlay) with the Escape key in certain scenarios:Root cause: The focus-return logic in
VOverlay.onKeydownwas gated behind a check that the active element was inside the overlay content at the time Escape was pressed:When focus was outside the content (e.g. still on the page body), the activator was never re-focused.
Fix
Remove the conditional so focus always returns to the activator when Escape closes an overlay:
If the activator is not focusable (e.g. a plain
<div>used for coordinate-based menus), thefocus()call is a silent no-op — same behaviour as before for those cases. For button-based activators this ensures focus is reliably returned.Also adds a browser test covering this scenario.