Skip to content

Commit

Permalink
[material-ui][Modal] Fix event handlers overriding behaviour (#43757)
Browse files Browse the repository at this point in the history
  • Loading branch information
sai6855 committed Sep 17, 2024
1 parent 15428ca commit e941175
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/mui-material/src/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ const Modal = React.forwardRef(function Modal(inProps, ref) {
}

const externalForwardedProps = {
...other,
slots: {
root: components.Root,
backdrop: components.Backdrop,
Expand Down Expand Up @@ -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}
Expand Down
16 changes: 16 additions & 0 deletions packages/mui-material/src/Modal/Modal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -880,4 +880,20 @@ describe('<Modal />', () => {
);
}).not.toErrorDev();
});

it('should not override default onKeyDown', async () => {
const handleKeyDown = spy();
const handleClose = spy();

const { user } = render(
<Modal open onKeyDown={handleKeyDown} onClose={handleClose}>
<div tabIndex={-1} />
</Modal>,
);

await user.keyboard('{Escape}');

expect(handleKeyDown).to.have.property('callCount', 1);
expect(handleClose).to.have.property('callCount', 1);
});
});

0 comments on commit e941175

Please sign in to comment.