Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[modal][material-ui] Cannot move focus outside even withdisableEnforceFocus #44258

Closed
Val020213 opened this issue Oct 29, 2024 · 4 comments
Closed
Assignees
Labels
component: modal This is the name of the generic UI component, not the React module! support: question Community support but can be turned into an improvement

Comments

@Val020213
Copy link

Val020213 commented Oct 29, 2024

Steps to reproduce

Link to live example: https://codesandbox.io/p/sandbox/hungry-brahmagupta-57h2pq

Steps to reproduce:

  1. Create a Snackbar message containing an Alert component with an onClose prop or another clickable component inside.
  2. Create a basic Modal component with the disableEnforceFocus prop set to true and a button that opens the Snackbar message.
  3. 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

@Val020213 Val020213 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 29, 2024
@mj12albert mj12albert changed the title [MODAL][Material UI] [modal][material-ui] Cannot move focus outside even withdisableEnforceFocus Oct 30, 2024
@mj12albert mj12albert added the component: modal This is the name of the generic UI component, not the React module! label Oct 30, 2024
@mj12albert mj12albert removed their assignment Nov 4, 2024
@mnajdova mnajdova self-assigned this Nov 4, 2024
@mnajdova mnajdova moved this to Selected in Material UI Nov 4, 2024
@mnajdova
Copy link
Member

mnajdova commented Nov 6, 2024

You seem to be looking for something like non-modal Dialog. We have a demo of how you can build one here: https://mui.com/material-ui/react-dialog/#non-modal-dialog

By definition the Modal blocks the interactions outside of it. You were close into setting up the prop on the TrapFocus, but the Modal also has additional logic for preventing this interactions (as it is by definition suppose to do it).

Even after setting the disableEnforceFocus prop on the Modal, it is not possible to access components outside the Modal when using the Tab key.

This is expected, what it means that you have still the circular tab index inside the component, but you can click or interact otherwise with the content outside of it (e.g. by having a keyboard shortcut to go outside of it).

@mnajdova mnajdova added support: question Community support but can be turned into an improvement and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 6, 2024
@mnajdova
Copy link
Member

mnajdova commented Nov 6, 2024

If you don't even want to trap focus, then no need to use the FocusTrap component, but I would recommend reading a bit about what's the expectation for users when using Modals, to make sure the app would still be accessible and work as expected.

@DiegoAndai DiegoAndai added the status: waiting for author Issue with insufficient information label Nov 11, 2024
@DiegoAndai DiegoAndai moved this from Selected to Waiting for response in Material UI Nov 11, 2024
@Val020213
Copy link
Author

Okay, I will do that. Thank you very much for the reference and the time you dedicated.

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Nov 12, 2024
@github-project-automation github-project-automation bot moved this from Waiting for response to Done in Material UI Nov 12, 2024
@github-actions github-actions bot removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Nov 12, 2024
Copy link

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

Note

@Val020213 How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: modal This is the name of the generic UI component, not the React module! support: question Community support but can be turned into an improvement
Projects
Status: Done
Development

No branches or pull requests

4 participants