You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Material UI: Pressing Escape key closes Dialog before Snackbar/Alert #44799
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.
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.
@g1hanna Thanks again for creating this issue! If you have a moment, we would love to hear your thoughts on how we handled it with this short feedback form.
Activity
mnajdova commentedon Dec 18, 2024
You can use the
disableEscapeKeyDownprop on the Dialog when the snackbar is open. This means that the Dialog will ignore the escape key while the snackbar is open, once it is closed it will be closed if the escape key is pressed. Check this CodeSandbox: https://codesandbox.io/p/sandbox/mui-dialog-toast-escape-example-forked-twt226?workspaceId=ws_LCQafiBEJ7ynffHYRMAZLmnajdova commentedon Dec 18, 2024
We can maybe extend a docs a bit to explain this, or add a demo. cc @samuelsycamore
minwookshin commentedon Oct 4, 2026
I’ll add a Dialog/Snackbar demo using the current
onCloseAPI, so the first Escape closes the snackbar and the next closes the dialog.github-actions commentedon Oct 7, 2026
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.
@g1hanna Thanks again for creating this issue! If you have a moment, we would love to hear your thoughts on how we handled it with this short feedback form.