Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[material-ui][Modal] Fix event handlers overriding behaviour #43757

Merged
merged 5 commits into from
Sep 17, 2024
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',
});
aarongarciah marked this conversation as resolved.
Show resolved Hide resolved

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