Skip to content

[Modal] Fix stale aria-hidden when the container changes - #48889

Open
atharv-sys32 wants to merge 1 commit into
mui:masterfrom
atharv-sys32:fix/aria-hidden-dialog-container
Open

[Modal] Fix stale aria-hidden when the container changes#48889
atharv-sys32 wants to merge 1 commit into
mui:masterfrom
atharv-sys32:fix/aria-hidden-dialog-container

Conversation

@atharv-sys32

Copy link
Copy Markdown

Fixes #48882

Root cause

When a Modal's container prop changes while the modal stays open, the modal is moved into the new container but the previous container keeps the aria-hidden state that was computed for the previous sibling set. For example, a modal mounted in document.body (default container) marks #root as aria-hidden; switching container to a node inside #root leaves #root hidden, making the dialog inaccessible to assistive technologies (getByRole('dialog') fails).

Changes

  • useModal: track the container the modal is registered with (registeredContainerRef) and re-register the modal with the ModalManager when the resolved container changes while open.
  • ModalManager: when removing the last modal of a container, restore siblings using the container itself as the blacklist entry instead of modal.mount. The mount node is already updated to the new container by the portal before the manager is notified, which previously kept the new container in the blacklist and left it aria-hidden.

Tests

  • ModalManager.test.ts: unit test covering the re-registration flow to a nested container.
  • Modal.test.js: regression test that changes the container prop after mount and asserts the previous container loses aria-hidden.

@code-infra-dashboard

code-infra-dashboard Bot commented Aug 1, 2026

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-48889--material-ui.netlify.app/
QR code for https://deploy-preview-48889--material-ui.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/material 🔺+110B(+0.02%) 🔺+39B(+0.03%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@atharv-sys32

Copy link
Copy Markdown
Author

Hi @ZeeshanTamboli, could you take a look when you get a chance? This fixes #48882 (stale aria-hidden when a Modal's container changes). All checks are passing, including a regression test that swaps the container after mount. A maintainer label on the PR would also let the remaining label check go green.

@atharv-sys32

atharv-sys32 commented Aug 3, 2026

Copy link
Copy Markdown
Author

Hi @ZeeshanTamboli @silviuaavram, quick nudge on this one. The fix is ready, all CI checks pass, and I added a regression test for the stale aria-hidden case. The test-label-applied check needs a maintainer to apply the label before this can merge. Would appreciate a review when you have a moment. Thanks!

@silviuaavram

Copy link
Copy Markdown
Member

@ZeeshanTamboli this seems to be in the same area as your current transition fix, that also checks whether the portal container changes. Can you sync the work and make sure there's no duplicated effort?

@ZeeshanTamboli

ZeeshanTamboli commented Aug 5, 2026

Copy link
Copy Markdown
Member

@ZeeshanTamboli this seems to be in the same area as your current transition fix, that also checks whether the portal container changes. Can you sync the work and make sure there's no duplicated effort?

@silviuaavram This is a bit different than the fix in the transition PR (#48881). I will review this PR later after the transition one is accepted and merged, incase if there is any duplication.

@github-actions github-actions Bot added PR: out-of-date The pull request has merge conflicts and can't be merged. and removed PR: out-of-date The pull request has merge conflicts and can't be merged. labels Aug 5, 2026
@atharv-sys32
atharv-sys32 force-pushed the fix/aria-hidden-dialog-container branch from 1ef9f63 to b7e5c8b Compare August 5, 2026 16:52
@atharv-sys32

Copy link
Copy Markdown
Author

Hi @ZeeshanTamboli, I rebased this branch on the latest master and resolved the conflicts that came up after your transition fix (#48881) landed. Both tests are kept: yours for the exit transition and mine for the stale aria-hidden case, they cover different scenarios. useModal.ts rebased cleanly with no duplicated logic. The PR is mergeable again and ready for review when you have a moment.

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

Labels

scope: modal Changes related to the modal.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

aria-hidden incorrectly set with Dialog container changes

5 participants