From 05098cc3763d6a74879ea0d2430dda4786e053e5 Mon Sep 17 00:00:00 2001 From: David Menc Date: Wed, 29 Oct 2025 13:51:36 +0100 Subject: [PATCH] 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. --- src/components/Modal/Modal.jsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/Modal/Modal.jsx b/src/components/Modal/Modal.jsx index 6212f22a..9749795a 100644 --- a/src/components/Modal/Modal.jsx +++ b/src/components/Modal/Modal.jsx @@ -76,7 +76,12 @@ export const Modal = ({ useModalScrollPrevention(preventScrollUnderneath); const onCancel = useCallback( - (e) => dialogOnCancelHandler(e, closeButtonRef, restProps.onCancel), + (e) => { + if (e.target !== internalDialogRef.current) { + return; + } + dialogOnCancelHandler(e, closeButtonRef, restProps.onCancel); + }, [closeButtonRef, restProps.onCancel], ); const onClick = useCallback(