fix(modal): keep focus on dialog for cycle sheet modals#31293
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
thetaPC
approved these changes
Jul 23, 2026
Comment on lines
+1178
to
+1183
| /** | ||
| * Shadow DOM focus is retargeted to the host, so `ev.target === el` is also | ||
| * true when a shadow child (the dialog wrapper present() focuses) is focused. | ||
| * shadowRoot's activeElement is null only when the host was focused directly, | ||
| * so redirect to the handle only then and leave present()'s wrapper focus intact. | ||
| */ |
Contributor
There was a problem hiding this comment.
I noticed that this comment is different than the one on major-9.0. I assume that this was intentional.
Member
Author
There was a problem hiding this comment.
Yeah, just a little more concise. I'll probably take this when I merge main into major-9.0
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.
Issue number: internal
What is the current behavior?
When a sheet modal uses
handleBehavior="cycle", the host element is focusable (tabIndex=0) andonModalFocusredirects focus to the drag handle whenever the host is focused.present()moves focus to the.modal-wrapper(therole="dialog"element) inside the shadow DOM, but that focus event is retargeted to the host, soonModalFocusseesev.target === eland treats it as a direct host focus. It then bounces focus onto the handle.This is latent on the default
handleBehavior="none"(the host isn't focusable, so the redirect never runs), but reproduces on any sheet modal that opts intocycle.What is the new behavior?
onModalFocusnow redirects to the handle only when the host itself was focused directly, detected byel.shadowRoot?.activeElementbeingnull. Whenpresent()focuses the dialog wrapper,activeElementis the wrapper (not null), so the redirect is skipped and the dialog keeps focus. Tabbing into the modal from outside still lands on the handle, since the host is the focused element in that case.Does this introduce a breaking change?
Other information
Related to the dialog focus work in #31260 . That change is correct under the default
handleBehavior, but thecyclepath was not covered until now. Adds an e2e test toutils/test/overlays/overlays.e2e.tsthat presents a sheet modal withhandle-behavior="cycle"and asserts focus stays on the wrapper.The same fix ships on the major-9.0 sync (#31290), where
cycleis the default and this bug is hit on every sheet modal.Preview (sheet modal test page):