From 6eee7c8e914b7e69563f9eec4feec707e7c8bc70 Mon Sep 17 00:00:00 2001 From: Vitaly Rtishchev Date: Sat, 12 Nov 2022 13:57:30 +0400 Subject: [PATCH] [core] Cleanup Modal code --- src/mantine-core/src/Modal/Modal.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/mantine-core/src/Modal/Modal.tsx b/src/mantine-core/src/Modal/Modal.tsx index bc0afc40d45..c9acafcac6e 100644 --- a/src/mantine-core/src/Modal/Modal.tsx +++ b/src/mantine-core/src/Modal/Modal.tsx @@ -208,14 +208,15 @@ export function Modal(props: ModalProps) { useFocusReturn({ opened, shouldReturnFocus: trapFocus && withFocusReturn }); const clickTarget = useRef(null); + useWindowEvent('mousedown', (e) => { clickTarget.current = e.target; }); const handleOutsideClick = () => { - if (clickTarget.current !== overlayRef.current) return; - - closeOnClickOutside && onClose(); + if (clickTarget.current === overlayRef.current) { + closeOnClickOutside && onClose(); + } }; return (