diff --git a/packages/kit-headless/src/components/modal/modal-popup.tsx b/packages/kit-headless/src/components/modal/modal-popup.tsx index 5045da6ed..8b7399d49 100644 --- a/packages/kit-headless/src/components/modal/modal-popup.tsx +++ b/packages/kit-headless/src/components/modal/modal-popup.tsx @@ -14,7 +14,6 @@ import { modalContextId } from './modal-context-id'; export const ModalPopup = component$( (props: Omit) => { - const { class: modalPopupClass, ...htmlDialogProps } = props; const modalContext = useContext(modalContextId); const refSig = useSignal(); @@ -61,23 +60,33 @@ export const ModalPopup = component$( }); const closeOnBackdropClick$ = $((event: QwikMouseEvent) => { - if ((event.target as Element).nodeName !== 'DIALOG') { + const modal = refSig.value; + + if (!modal) { return; } - modalContext.showSig.value = false; + const modalRect = modal.getBoundingClientRect(); + + const wasClickTriggeredOutsideModalRect = + modalRect.left > event.clientX || + modalRect.right < event.clientX || + modalRect.top > event.clientY || + modalRect.bottom < event.clientY; + + if (wasClickTriggeredOutsideModalRect) { + modalContext.showSig.value = false; + } }); return ( closeOnBackdropClick$(event)} onClose$={() => (modalContext.showSig.value = false)} > -
- -
+
); },