File tree 1 file changed +16
-7
lines changed
packages/kit-headless/src/components/modal
1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ import { modalContextId } from './modal-context-id';
14
14
15
15
export const ModalPopup = component$ (
16
16
( props : Omit < QwikIntrinsicElements [ 'dialog' ] , 'open' > ) => {
17
- const { class : modalPopupClass , ...htmlDialogProps } = props ;
18
17
const modalContext = useContext ( modalContextId ) ;
19
18
const refSig = useSignal < HTMLDialogElement > ( ) ;
20
19
@@ -61,23 +60,33 @@ export const ModalPopup = component$(
61
60
} ) ;
62
61
63
62
const closeOnBackdropClick$ = $ ( ( event : QwikMouseEvent ) => {
64
- if ( ( event . target as Element ) . nodeName !== 'DIALOG' ) {
63
+ const modal = refSig . value ;
64
+
65
+ if ( ! modal ) {
65
66
return ;
66
67
}
67
68
68
- modalContext . showSig . value = false ;
69
+ const modalRect = modal . getBoundingClientRect ( ) ;
70
+
71
+ const wasClickTriggeredOutsideModalRect =
72
+ modalRect . left > event . clientX ||
73
+ modalRect . right < event . clientX ||
74
+ modalRect . top > event . clientY ||
75
+ modalRect . bottom < event . clientY ;
76
+
77
+ if ( wasClickTriggeredOutsideModalRect ) {
78
+ modalContext . showSig . value = false ;
79
+ }
69
80
} ) ;
70
81
71
82
return (
72
83
< dialog
73
- { ...htmlDialogProps }
84
+ { ...props }
74
85
ref = { refSig }
75
86
onClick$ = { ( event ) => closeOnBackdropClick$ ( event ) }
76
87
onClose$ = { ( ) => ( modalContext . showSig . value = false ) }
77
88
>
78
- < div class = { modalPopupClass } >
79
- < Slot />
80
- </ div >
89
+ < Slot />
81
90
</ dialog >
82
91
) ;
83
92
} ,
You can’t perform that action at this time.
0 commit comments