Skip to content

Commit dbbd7d2

Browse files
author
David Menc
committed
Fix modal closing when Escape key is pressed inside a OS dialog
Fixes a behavior when, for example a file open dialog is open in a Modal and the Escape key is pressed, the dialog and modal closes.
1 parent a815992 commit dbbd7d2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/components/Modal/Modal.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ export const Modal = ({
7676
useModalScrollPrevention(preventScrollUnderneath);
7777

7878
const onCancel = useCallback(
79-
(e) => dialogOnCancelHandler(e, closeButtonRef, restProps.onCancel),
79+
(e) => {
80+
if (e.target !== internalDialogRef.current) {
81+
return;
82+
}
83+
dialogOnCancelHandler(e, closeButtonRef, restProps.onCancel);
84+
},
8085
[closeButtonRef, restProps.onCancel],
8186
);
8287
const onClick = useCallback(

0 commit comments

Comments
 (0)