Steps to reproduce
Steps:
- Open this link to live example: https://codesandbox.io/p/devbox/patient-frost-x4rgvs?from-embed=&workspaceId=ws_Q9rT7Lz72nradL4qgt4vA4
- Note that
div#root has aria-hidden set. This is hiding all React content including the modal
- 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
Steps to reproduce
Steps:
div#roothas aria-hidden set. This is hiding all React content including the modalCurrent behavior
The dialog is hidden for accessibility testing because its ancestor,
div#root, is marked asaria-hidden.This was set by the
ModalManageron the first render becausediv#rootwas 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#rootwhich is still marked asaria-hiddenExpected 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-hiddenfromdiv#rootwhen 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#rootin 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 thearia-hiddenis 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/envinfoTested this in Chrome 150.0.7871.187 on Windows
Search keywords: Dialog Modal aria-hidden container