Description
Steps to reproduce
Link to live example: https://codesandbox.io/p/sandbox/hungry-brahmagupta-57h2pq
Steps to reproduce:
- Create a Snackbar message containing an Alert component with an
onClose
prop or another clickable component inside. - Create a basic Modal component with the
disableEnforceFocus
prop set totrue
and a button that opens the Snackbar message. - Observe that when using the Tab key, it’s not possible to navigate to interactive components outside the Modal.
Current behavior
Current Behavior: Even after setting the disableEnforceFocus
prop on the Modal, it is not possible to access components outside the Modal when using the Tab key.
Expected behavior
Expected Behavior: According to the Focus trap section in the MUI documentation, the Modal component will move focus back to the body if focus tries to escape it. This is implemented for accessibility purposes but may create usability issues.
However, when using <Modal disableEnforceFocus />
, it should be possible to close the Snackbar or interact with other components on the page.
Context
I'm trying to create an accessible user experience where users can open a Snackbar notification from within a Modal, interact with the Snackbar (e.g., close it with an onClose action), and still be able to tab to other interactive components outside the Modal. Setting disableEnforceFocus on the Modal doesn't seem to allow this as expected, so I'm unable to create the intended experience.
I have a global Snackbar provider for my app, where all toast messages are dispatched. Any toast message that isn't opened within the Modal body becomes unfocusable, which disrupts accessibility. Any guidance on enabling this behavior would be greatly appreciated.
Your environment
npx @mui/envinfo
System:
OS: Windows 11 10.0.22631
Binaries:
Node: 20.11.0 - C:\Program Files\nodejs\node.EXE
npm: 10.3.0 - C:\Program Files\nodejs\npm.CMD
pnpm: 8.15.4 - ~\AppData\Roaming\npm\pnpm.CMD
Browsers:
Chrome: Not Found
Edge: Chromium (128.0.2739.67)
Search keywords: disableEnforceFocus, ada, accessibility, modal, trapFocus
Metadata
Metadata
Assignees
Labels
Projects
Status