Material UI: Pressing Escape key closes Dialog before Snackbar/Alert
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 99.1k
- Forks
- 32.5k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 106
Description
Steps to reproduce
Steps:
- Open this link to live example: MUI-Dialog-Toast-Escape-Example
- Press "Open Modal" to open the Dialog
- Press "Open Toast" to open the Snackbar Alert
- Press the Escape key
Current behavior
When the Escape key is pressed, the Dialog is closed first and the Alert is still displayed.
Expected behavior
Not sure what behavior should be enabled by default. Was expecting the layers to be closed in the order the user opened them (Toast on the first Escape key press, then the Modal on the second press). Ideally, we'd like to see a quick and easy way to configure this behavior.
Context
I am trying to implement a feature for a common use case in a production-facing React application. There are 50+ pages where a user can have both MUI Alerts and Dialogs open simultaneously. We need a solution that doesn't cause components that use Dialogs to be dependent on the open state of Snackbar or Alert components. We have been searching the MUI documentation and StackOverflow for this particular use case, but it has not come up in searches.
Your environment
npx @mui/envinfo
System:
OS: Linux 5.15 Ubuntu 20.04.6 LTS (Focal Fossa)
Binaries:
Node: 18.18.0 - ~/.nvm/versions/node/v18.18.0/bin/node
npm: 9.8.1 - ~/.nvm/versions/node/v18.18.0/bin/npm
pnpm: Not Found
Browsers:
Chrome: Version 131.0.6778.140 (Official Build) (64-bit)
npmPackages:
@emotion/react: ^11.13.3 => 11.13.3
@emotion/styled: ^11.13.0 => 11.13.0
@mui/base: 5.0.0-beta.58
@mui/core-downloads-tracker: 6.1.3
@mui/icons-material: ^6.1.1 => 6.1.3
@mui/lab: ^6.0.0-beta.10 => 6.0.0-beta.11
@mui/material: ^6.1.1 => 6.1.3
@mui/material-nextjs: ^6.1.1 => 6.1.3
@mui/private-theming: 6.1.3
@mui/styled-engine: 6.1.3
@mui/system: ^6.1.1 => 6.1.3
@mui/types: 7.2.18
@mui/utils: 5.16.6
@mui/x-data-grid: ^7.18.0 => 7.19.0
@mui/x-data-grid-pro: ^7.18.0 => 7.19.0
@mui/x-date-pickers: 7.19.0
@mui/x-date-pickers-pro: ^7.18.0 => 7.19.0
@mui/x-internals: 7.18.0
@mui/x-license: 7.18.0
@mui/x-tree-view: ^7.18.0 => 7.19.0
@types/react: ^18.3.9 => 18.3.11
react: 18.3.1 => 18.3.1
react-dom: ^18.2.0 => 18.3.1
typescript: ^5.6.2 => 5.6.3
Search keywords: Dialog Snackbar Alert Escape
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the behavior in the linked MUI-Dialog-Toast-Escape-Example with the reported React and Material UI versions, then trace how Dialog and Snackbar/Alert handle Escape events. The issue does not name repository files or tests; completion depends on an agreed default or configuration for the closing order, followed by a regression test for that behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- accessibility, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100