From e941175a06b052f5cbc854fda872798ced1ed6a0 Mon Sep 17 00:00:00 2001 From: sai chand <60743144+sai6855@users.noreply.github.com> Date: Tue, 17 Sep 2024 16:48:01 +0530 Subject: [PATCH] [material-ui][Modal] Fix event handlers overriding behaviour (#43757) --- packages/mui-material/src/Modal/Modal.js | 3 ++- packages/mui-material/src/Modal/Modal.test.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/mui-material/src/Modal/Modal.js b/packages/mui-material/src/Modal/Modal.js index 60d29549ff74ae..bbb78393680047 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 */} - + {!hideBackdrop && BackdropComponent ? ( ) : null} diff --git a/packages/mui-material/src/Modal/Modal.test.js b/packages/mui-material/src/Modal/Modal.test.js index dd4da576fde15f..872a5e18460c73 100644 --- a/packages/mui-material/src/Modal/Modal.test.js +++ b/packages/mui-material/src/Modal/Modal.test.js @@ -880,4 +880,20 @@ describe('', () => { ); }).not.toErrorDev(); }); + + it('should not override default onKeyDown', async () => { + const handleKeyDown = spy(); + const handleClose = spy(); + + const { user } = render( + +
+ , + ); + + await user.keyboard('{Escape}'); + + expect(handleKeyDown).to.have.property('callCount', 1); + expect(handleClose).to.have.property('callCount', 1); + }); });