fix(react-dialog): stale aria-hidden breaks focus trap when closing stacked non-nested sibling dialogs#35990
Draft
fix(react-dialog): stale aria-hidden breaks focus trap when closing stacked non-nested sibling dialogs#35990
Conversation
…ed dialogs close (#35985) Agent-Logs-Url: https://github.com/microsoft/fluentui/sessions/fc8d830a-fba4-4001-91af-89f9e553572e Co-authored-by: Hotell <1223799+Hotell@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix aria-hidden issue when closing sibling dialogs
fix(react-dialog): stale aria-hidden breaks focus trap when closing stacked non-nested sibling dialogs
Apr 15, 2026
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.
When two sibling (non-nested)
Dialogcomponents are stacked, closing the top dialog leaves a stalearia-hidden="true"on the underlying dialog's portal mount node — set by the underlying dialog's own Modalizer — blocking the browser from restoring focus back into it. Tabster's Modalizer does not currently maintain an activation stack, so the stale attribute is never cleaned up.Changes
useFocusFirstElement.ts— AddedremoveStaleAriaHiddenFromAncestorswhich walks ancestor nodes of the dialog surface up to<body>and strips anyaria-hidden="true"before attempting focus. Runs only whenopen === true(Modalizer is active); a TODO marks removal once Tabster supports a proper activation stack.Dialog.cy.tsx— Addeddescribe('stacked non-nested dialogs (sibling)')with three Cypress regression tests:aria-hidden="true"after Dialog 2 closesChange file — Patch bump for
@fluentui/react-dialog.Example scenario
Original prompt
Context
This PR addresses #35985: when two independent (non-nested, sibling)
Dialogcomponents are stacked — e.g. Dialog 1 is open, and from a button inside it Dialog 2 is opened programmatically — closing Dialog 2 leaves a stalearia-hidden="true"on Dialog 1's portal mount node. This blocks browser focus from entering that subtree, so the Tabster Restorer fires focus back to the original page-level trigger rather than back into Dialog 1.Root cause
Each
Dialogindependently callsuseModalAttributeswhich configures a Tabster Modalizer + Restorer pair. When Dialog 2's Modalizer activates, itaria-hiddens everything outside itself, including Dialog 1's portal. When Dialog 2 unmounts, its Modalizer cleanup removes thearia-hiddenit set. However, Dialog 1 is still open and its own Modalizer'saria-hiddenwalk marked Dialog 1's portal container as hidden from its own perspective. The net result is a stalearia-hidden="true"left on Dialog 1's portal node after Dialog 2 closes. The browser refuses.focus()into anaria-hiddensubtree, soRestorerTypes.Targetfocus restoration silently fails and focus bubbles up to the page-level trigger.The ultimate fix belongs in Tabster's Modalizer (it should maintain an activation stack). Until that lands, a client-side mitigation is needed in
useFocusFirstElement.Required changes
1. Cypress regression test
File:
packages/react-components/react-dialog/library/src/components/Dialog/Dialog.cy.tsxAdd a new
describe('stacked non-nested dialogs (sibling)', ...)block appended after the existing'should allow nested dialogs'test (after line 702, before the closing});of the top-leveldescribe('Dialog', ...)).The block should use the existing imports already present in the file (
React,Button,Dialog,DialogSurface,DialogBody,DialogTitle,DialogContent,DialogActions,DialogTrigger, and the selectorsdialogTriggerOpenId,dialogTriggerOpenSelector,dialogTriggerCloseId,dialogTriggerCloseSelector,dialogSurfaceSelector).Add this describe block: