Skip to content

aria-hidden incorrectly set with Dialog container changes #48882

Description

@angrycat9000

Steps to reproduce

Steps:

  1. Open this link to live example: https://codesandbox.io/p/devbox/patient-frost-x4rgvs?from-embed=&workspaceId=ws_Q9rT7Lz72nradL4qgt4vA4
  2. Note that div#root has aria-hidden set. This is hiding all React content including the modal
  3. If you close and reopen the dialog. aria-hidden is not set.

Current behavior

The dialog is hidden for accessibility testing because its ancestor, div#root, is marked as aria-hidden.

This was set by the ModalManager on the first render because div#root was a sibling of the dialog on the first render.

On the second render the container ref changes and the dialog is now inside of div#root which is still marked as aria-hidden

Expected behavior

When the container for a modal is changed, the ModalManager should re-evaluate which elements should be aria-hidden. It should remove the aria-hidden from div#root when it is no longer a sibiling of the modal.

The state should be the same as if the dialog container was always set to be inside div#root in the same render it was set to be opened.

Context

This bug occurred in automated testing. The test is attempting to use getByRole('dialog') to locate the dialog. However because the aria-hidden is incorrectly set, on the render root, it considers everything inaccessible and it fails to locate the dialog.

Similar to but not identical:

Your environment

npx @mui/envinfo

Tested this in Chrome 150.0.7871.187 on Windows

  System:
    OS: Linux 6.18 Ubuntu 24.04.4 LTS 24.04.4 LTS (Noble Numbat)
  Binaries:
    Node: 24.15.0 - /home/codespace/nvm/current/bin/node
    npm: 11.12.1 - /home/codespace/nvm/current/bin/npm
    pnpm: 10.30.1 - /home/codespace/nvm/current/bin/pnpm
  Browsers:
    Chrome: Not Found
    Firefox: Not Found
  npmPackages:
    typescript: catalog: => 6.0.3 

Search keywords: Dialog Modal aria-hidden container

Metadata

Metadata

Assignees

Labels

duplicateThis issue or pull request already exists.scope: dialogChanges related to the dialog.scope: modalChanges related to the modal.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions