From e1162631c45629605cde1b0700cb24ab1ac54ba0 Mon Sep 17 00:00:00 2001 From: sai6855 Date: Sat, 14 Sep 2024 21:06:15 +0530 Subject: [PATCH 1/3] fix event handlers overriding behaviour --- packages/mui-material/src/Modal/Modal.js | 3 ++- packages/mui-material/src/Modal/Modal.test.js | 20 +++++++++++++++++++ 2 files changed, 22 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..0769abc6897d28 100644 --- a/packages/mui-material/src/Modal/Modal.test.js +++ b/packages/mui-material/src/Modal/Modal.test.js @@ -880,4 +880,24 @@ describe('', () => { ); }).not.toErrorDev(); }); + + it('should not override default onKeyDown', () => { + const handleKeyDown = spy(); + const handleClose = spy(); + const { getByTestId } = render( + +
+ , + ); + act(() => { + getByTestId('modal').focus(); + }); + + fireEvent.keyDown(getByTestId('modal'), { + key: 'Escape', + }); + + expect(handleKeyDown).to.have.property('callCount', 1); + expect(handleClose).to.have.property('callCount', 1); + }); }); From a667017dfcdbb20d7064eaa38c95203ea5b319a2 Mon Sep 17 00:00:00 2001 From: sai6855 Date: Sat, 14 Sep 2024 22:30:10 +0530 Subject: [PATCH 2/3] trigger From a475aa73fc6d33f494d83db36bc5b7211cd19faf Mon Sep 17 00:00:00 2001 From: sai6855 Date: Tue, 17 Sep 2024 15:55:30 +0530 Subject: [PATCH 3/3] modify test --- packages/mui-material/src/Modal/Modal.test.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/mui-material/src/Modal/Modal.test.js b/packages/mui-material/src/Modal/Modal.test.js index 0769abc6897d28..872a5e18460c73 100644 --- a/packages/mui-material/src/Modal/Modal.test.js +++ b/packages/mui-material/src/Modal/Modal.test.js @@ -881,21 +881,17 @@ describe('', () => { }).not.toErrorDev(); }); - it('should not override default onKeyDown', () => { + it('should not override default onKeyDown', async () => { const handleKeyDown = spy(); const handleClose = spy(); - const { getByTestId } = render( + + const { user } = render( -
+
, ); - act(() => { - getByTestId('modal').focus(); - }); - fireEvent.keyDown(getByTestId('modal'), { - key: 'Escape', - }); + await user.keyboard('{Escape}'); expect(handleKeyDown).to.have.property('callCount', 1); expect(handleClose).to.have.property('callCount', 1);