Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 20 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,24 @@ describe('<Modal />', () => {
);
}).not.toErrorDev();
});

it('should not override default onKeyDown', () => {
const handleKeyDown = spy();
const handleClose = spy();
const { getByTestId } = render(
<Modal open onKeyDown={handleKeyDown} onClose={handleClose}>
<div data-testid="modal" tabIndex={-1} />
</Modal>,
);
act(() => {
getByTestId('modal').focus();
});

fireEvent.keyDown(getByTestId('modal'), {
key: 'Escape',
});

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