Skip to content

Conversation

@p-nadeem
Copy link

Description

This PR improves the keyboard accessibility of the Snackbar component by adding an F6 keyboard shortcut that moves focus directly to the Snackbar when it is open. This makes it easier for keyboard users to access dynamic snackbars and their interactive elements (such as the close button or links) without having to tab through the entire page.

Changes

  • Updated the Snackbar implementation to:
    • Register a keydown listener when the Snackbar is open and handle the F6 key.
    • Focus the Snackbar container when F6 is pressed.
    • Make the Snackbar container focusable by default with tabIndex={0}.
    • Expose the Snackbar container as a live region with role="status" for assistive technologies.
  • Updated the Snackbar docs (docs/data/material/components/snackbars/snackbars.md) to document:
    • The new F6 shortcut under the Accessibility → Keyboard navigation section.
    • How the shortcut helps keyboard users reach the Snackbar without traversing the full page.
  • Added unit tests for:
    • Focusing the Snackbar when F6 is pressed.
    • Ensuring no focus change occurs when the Snackbar is closed.
    • Verifying role="status" is applied to the Snackbar.
    • Verifying tabIndex="0" is applied so the Snackbar is focusable.
    • Ensuring the behavior works correctly when multiple Snackbars are open.

Related issue

Fixes #45243

Additional

@mui-bot
Copy link

mui-bot commented Dec 11, 2025

Netlify deploy preview

Bundle size report

Bundle Parsed size Gzip size
@mui/material 🔺+305B(+0.06%) 🔺+59B(+0.04%)
@mui/lab 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

Generated by 🚫 dangerJS against f113670

@p-nadeem p-nadeem marked this pull request as draft December 11, 2025 05:50
@p-nadeem p-nadeem closed this Dec 11, 2025
@p-nadeem p-nadeem reopened this Dec 11, 2025
@p-nadeem p-nadeem changed the title [material-ui][Snackbar] Add F6 keyboard shortcut for accessibility [Snackbar] Add F6 keyboard shortcut for accessibility Dec 11, 2025
@p-nadeem p-nadeem marked this pull request as ready for review December 11, 2025 06:08
@zannager zannager added docs Improvements or additions to the documentation. scope: toast Changes related to the toast. labels Dec 12, 2025
@ZeeshanTamboli
Copy link
Member

ZeeshanTamboli commented Dec 15, 2025

@siriwatknp Do you think we should support this in Material UI like in Base UI Toast?

@mj12albert
Copy link
Member

Do you think we should support this in Material UI like in Base UI Toast?

Unlike Base UI, the Material UI snackbar is already part of the tab sequence – if you open the first snackbar with keyboard, the next 2 tab stops become the undo and X buttons inside the snackbar

So IMO the hotkey only makes sense if the popup contents are otherwise inaccessible via keyboard

@ZeeshanTamboli
Copy link
Member

ZeeshanTamboli commented Dec 16, 2025

Do you think we should support this in Material UI like in Base UI Toast?

Unlike Base UI, the Material UI snackbar is already part of the tab sequence – if you open the first snackbar with keyboard, the next 2 tab stops become the undo and X buttons inside the snackbar

So IMO the hotkey only makes sense if the popup contents are otherwise inaccessible via keyboard

So, is this issue not relevant: #45243? Don't remember why I had commented that we can add support for F6.

@mj12albert
Copy link
Member

@ZeeshanTamboli Maybe it's still worth adding depending on the "dynamic snackbar" case mentioned in the original issue, do you have any idea what that is?

the Material UI snackbar is already part of the tab sequence

The hotkey would be great if this behavior didn't already exist, technically it may be breaking to change it? Or we could consider it a bug and never intended to begin with

@ZeeshanTamboli
Copy link
Member

@ZeeshanTamboli Maybe it's still worth adding depending on the "dynamic snackbar" case mentioned in the original issue, do you have any idea what that is?

I wonder "dynamic snackbar" would be when it is controlled by state or events. But I don't see even then how the tab focusing wouldn't work for the issue author.

the Material UI snackbar is already part of the tab sequence

The hotkey would be great if this behavior didn't already exist, technically it may be breaking to change it? Or we could consider it a bug and never intended to begin with

We can't change it. It would be a breaking change.

@mj12albert
Copy link
Member

mj12albert commented Dec 17, 2025

We could add the hotkey, then open an issue for future removal of the Snackbar being part of the tab sequence ever; having both isn't the end of the world, but the hotkey would be the correct (and documented) way of moving keyboard focus to the snackbar

@ZeeshanTamboli
Copy link
Member

We could add the hotkey, then open an issue for future removal of the Snackbar being part of the tab sequence ever; having both isn't the end of the world, but the hotkey would be the correct (and documented) way of moving keyboard focus to the snackbar

But since the advent of Snackbar, we haven't seen issues about not being able to focus it or its contents, which suggests people are relying on normal Tab navigation. Given that, IMO, adding a hotkey besides supporting Tab navigation doesn't seem worth adding it right now, especially since it would increase bundle size. I think the best next step is to wait for the issue author to clarify their use case.

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

Labels

docs Improvements or additions to the documentation. scope: toast Changes related to the toast.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[docs] MUI Snackbar Accessibility

5 participants