mui / material-ui

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
https://mui.com/material-ui/
MIT License
93.36k stars 32.13k forks source link

[Dialog] Providing onKeyDown breaks closing via Escape #43738

Closed hvolschenk closed 18 hours ago

hvolschenk commented 5 days ago

Steps to reproduce

Link to live example: codesandbox

Steps:

  1. Validate that pressing escape does not close the <Dialog />.
  2. Comment out the onKeyDown line.
  3. Validate that pressing escape does now close the <Dialog />.

Current behavior

When an onKeyDown handler is passed to the <Dialog /> component, the Escape key does not work to close the <Dialog /> anymore.

Expected behavior

Just like it used to in v5, the <Dialog /> should close when pressing Escape even when an onKeyDown is supplied in v6.

Context

No response

Your environment

Check the codesandbox.

Search keywords: dialog, onKeyDown, escape

oliviertassinari commented 4 days ago

I guess it's simply that the Modal doesn't follow the template, it should be?

diff --git a/packages/mui-material/src/Modal/Modal.js b/packages/mui-material/src/Modal/Modal.js
index 60d29549ff..bbb7839368 100644
--- a/packages/mui-material/src/Modal/Modal.js
+++ b/packages/mui-material/src/Modal/Modal.js
@@ -156,6 +156,7 @@ const Modal = React.forwardRef(function Modal(inProps, ref) {
   }

   const externalForwardedProps = {
+    ...other,
     slots: {
       root: components.Root,
       backdrop: components.Backdrop,
@@ -218,7 +219,7 @@ const Modal = React.forwardRef(function Modal(inProps, ref) {
        * is not meant for humans to interact with directly.
        * https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-static-element-interactions.md
        */}
-      <RootSlot {...rootProps} {...other}>
+      <RootSlot {...rootProps}>
         {!hideBackdrop && BackdropComponent ? (
           <BackdropSlot {...backdropProps} ref={backdropRef} />
         ) : null}
KirankumarAmbati commented 4 days ago

@oliviertassinari I would like to work on it.

github-actions[bot] commented 18 hours ago

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] We value your feedback @hvolschenk! How was your experience with our support team? If you could spare a moment, we'd love to hear your thoughts in this brief Support Satisfaction survey. Your insights help us improve!