Skip to content

Commit e941175

Browse files
authored
[material-ui][Modal] Fix event handlers overriding behaviour (#43757)
1 parent 15428ca commit e941175

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/mui-material/src/Modal/Modal.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ const Modal = React.forwardRef(function Modal(inProps, ref) {
156156
}
157157

158158
const externalForwardedProps = {
159+
...other,
159160
slots: {
160161
root: components.Root,
161162
backdrop: components.Backdrop,
@@ -218,7 +219,7 @@ const Modal = React.forwardRef(function Modal(inProps, ref) {
218219
* is not meant for humans to interact with directly.
219220
* https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-static-element-interactions.md
220221
*/}
221-
<RootSlot {...rootProps} {...other}>
222+
<RootSlot {...rootProps}>
222223
{!hideBackdrop && BackdropComponent ? (
223224
<BackdropSlot {...backdropProps} ref={backdropRef} />
224225
) : null}

packages/mui-material/src/Modal/Modal.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,4 +880,20 @@ describe('<Modal />', () => {
880880
);
881881
}).not.toErrorDev();
882882
});
883+
884+
it('should not override default onKeyDown', async () => {
885+
const handleKeyDown = spy();
886+
const handleClose = spy();
887+
888+
const { user } = render(
889+
<Modal open onKeyDown={handleKeyDown} onClose={handleClose}>
890+
<div tabIndex={-1} />
891+
</Modal>,
892+
);
893+
894+
await user.keyboard('{Escape}');
895+
896+
expect(handleKeyDown).to.have.property('callCount', 1);
897+
expect(handleClose).to.have.property('callCount', 1);
898+
});
883899
});

0 commit comments

Comments
 (0)