Repository navigation
[dialog] Return focus inside the parent modal when a nested trigger is removed - #6047
Closed
FelixFangX wants to merge 3 commits into
Closed
FelixFangX wants to merge 3 commits into
FelixFangX wants to merge 3 commits into
Conversation
FelixFangX
requested review from
atomiks,
colmtuite,
flaviendelangle,
jjenzz and
michaldudak
as code owners
October 21, 2026 06:31
commit: |
Bundle size
PerformanceNo regressions in 36 benchmarks · ran 4m 30s · details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
FelixFangX
force-pushed
the
fix/nested-dialog-focus-return
branch
2 times, most recently
from
October 27, 2026 02:49
0104e16 to
5f7d85e
Compare
FelixFangX
force-pushed
the
fix/nested-dialog-focus-return
branch
from
October 28, 2026 02:43
5f7d85e to
e939121
Compare
…s removed When a nested dialog closed and both its trigger and the element focused before it opened were gone, the focus manager fell back to the global focus history, which could pick an element behind the still-open parent modal. The fallback now skips elements marked inert by an open modal, and falls back to the enclosing modal's popup when nothing eligible is left. The return target is resolved when the queued focus runs, after the closing popup's own inert markers are removed. Fixes #6037
FelixFangX
force-pushed
the
fix/nested-dialog-focus-return
branch
from
October 28, 2026 08:08
e939121 to
85bbee8
Compare
Author
|
Closing for now: open for 5+ days with no maintainer follow-up. Happy to reopen if you want this change. |
Contributor
|
Sorry for the silence on this one, and thanks for the fix! I pushed two commits on top:
Both come with regression tests. Reopening so we can land it. |
Author
|
Closing to reduce open external PR noise. Happy to reopen if maintainers want this change. |
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 #6037
Cause
When a popup closes and both its trigger and the element focused before it opened are disconnected,
getReturnElementinFloatingFocusManagerfalls back to the global focus history viagetPreviouslyFocusedElement(). For a nested dialog whose trigger was removed, the newest connected entry is the parent dialog's trigger, which sits behind the still-open parent modal. The parent'srestoreFocushandling only acts when focus lands onbody, so nothing corrects it.Fix
getPreviouslyFocusedElement(true), so it skips elements markeddata-base-ui-inert(outside an open modal) or hidden.FloatingFocusManagerprovides its floating element through a small context for this. Dialogs don't register floating tree nodes, so the tree can't be used to find the parent here.markOthersmarkers are still applied, so the inert filter would also skip valid background elements when a top-level modal closes (this broke the existing "returns focus to last connected element" test).If the trigger is still mounted, nothing changes: focus returns to it as before.
Tests
Added two cases to
dialogRootSharedTests, so they run for bothDialogandAlertDialognested in aDialog:Ran
pnpm test:jsdomandpnpm test:chromiumfor FloatingFocusManager, Dialog, AlertDialog, Popover, Menu, Drawer, Select and Combobox (plus Tooltip, NavigationMenu and PreviewCard in jsdom). All pass.pnpm typescript, ESLint and Prettier pass on the changed files.#5537 reworks focus return more broadly. This is a smaller fix for the current code.