File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -72,9 +72,20 @@ function handleGlobalKeyup() {
7272 showKbdHints .value = false
7373}
7474
75+ /* A hack to get light dismiss to work in safari because it does not support closedby="any" yet */
76+ // https://codepen.io/paramagicdev/pen/gbYompq
77+ // see: https://github.com/npmx-dev/npmx.dev/pull/522#discussion_r2749978022
78+ function handleModalLightDismiss(e : any ) {
79+ const modal = document .querySelector <HTMLDialogElement >(' dialog:modal' )
80+ if (modal && modal .open && ! e .composedPath ().includes (modal )) {
81+ modal .close ()
82+ }
83+ }
84+
7585if (import .meta .client ) {
7686 useEventListener (document , ' keydown' , handleGlobalKeydown )
7787 useEventListener (document , ' keyup' , handleGlobalKeyup )
88+ useEventListener (document , ' click' , handleModalLightDismiss )
7889}
7990 </script >
8091
Original file line number Diff line number Diff line change @@ -559,27 +559,3 @@ input[type='search']::-webkit-search-results-decoration {
559559html : has (dialog : modal ) {
560560 overflow : hidden;
561561}
562-
563- /* Backdrop styling when any of the modals are open */
564- dialog : modal ::backdrop {
565- @apply bg-black/60;
566- }
567-
568- /* Modal transition styles */
569- dialog {
570- opacity : 0 ;
571- transition : opacity 200ms ease;
572- transition-behavior : allow-discrete;
573- }
574-
575- dialog : modal {
576- opacity : 1 ;
577- transition : opacity 200ms ease;
578- transition-behavior : allow-discrete;
579- }
580-
581- @starting-style {
582- dialog [modal ] {
583- opacity : 0 ;
584- }
585- }
Original file line number Diff line number Diff line change @@ -37,3 +37,33 @@ function handleModalClose() {
3737 </dialog >
3838 </Teleport >
3939</template >
40+
41+ <style scoped>
42+ /* Backdrop styling when any of the modals are open */
43+ dialog :modal::backdrop {
44+ @apply bg-black /60;
45+ }
46+
47+ dialog ::backdrop {
48+ pointer-events : none ;
49+ }
50+
51+ /* Modal transition styles */
52+ dialog {
53+ opacity : 0 ;
54+ transition : opacity 200ms ease ;
55+ transition-behavior : allow-discrete;
56+ }
57+
58+ dialog :modal {
59+ opacity : 1 ;
60+ transition : opacity 200ms ease ;
61+ transition-behavior : allow-discrete;
62+ }
63+
64+ @starting-style {
65+ dialog :modal {
66+ opacity : 0 ;
67+ }
68+ }
69+ </style >
You can’t perform that action at this time.
0 commit comments