5
5
<Menu .Trigger >
6
6
<slot name =" button" ></slot >
7
7
</Menu .Trigger >
8
- <div @mousedown =" open = false" @touchstart =" open = false" v-if =" open" class =" fixed inset-0 z-10 bg-black/50" >
9
- </div >
10
- <Menu .Positioner :class =" isSmallScreen && '!bottom-0 !top-[unset] fixed inset-x-0 w-full !translate-y-0'" >
11
- <transition enter-active-class =" transition ease-in duration-100"
12
- enter-from-class =" transform opacity-0 translate-y-full sm:translate-y-0 scale-95"
13
- enter-to-class =" transform translate-y-0 opacity-100 scale-100"
14
- leave-active-class =" transition ease-out duration-75" leave-from-class =" transform opacity-100 scale-100"
15
- leave-to-class =" transform opacity-0 scale-95" >
16
- <Menu .Content v-if =" open"
17
- :class =" ['z-20 mt-2 rounded overflow-hidden p-1 space-y-1 bg-dark-700 shadow-lg ring-1 ring-white/10 focus:outline-none min-w-56']" >
18
- <div v-if =" isSmallScreen" class =" w-full py-2" >
19
- <div class =" rounded-full h-1 bg-gray-400 w-12 mx-auto" ></div >
20
- </div >
21
- <slot name =" items" ></slot >
22
- </Menu .Content >
23
- </transition >
24
- </Menu .Positioner >
8
+
9
+ <Teleport to =" body" >
10
+ <div @mousedown =" open = false" @touchstart =" open = false" v-if =" open"
11
+ class =" fixed inset-0 z-10 bg-black/50" >
12
+ </div >
13
+ <Menu .Positioner :class =" isSmallScreen && '!bottom-0 !top-[unset] fixed inset-x-0 w-full !translate-y-0'" >
14
+ <transition enter-active-class =" transition ease-in duration-100"
15
+ enter-from-class =" transform opacity-0 translate-y-full sm:translate-y-0 scale-95"
16
+ enter-to-class =" transform translate-y-0 opacity-100 scale-100"
17
+ leave-active-class =" transition ease-out duration-75"
18
+ leave-from-class =" transform opacity-100 scale-100" leave-to-class =" transform opacity-0 scale-95" >
19
+ <Menu .Content v-if =" open"
20
+ :class =" ['z-20 mt-2 rounded overflow-hidden p-1 space-y-1 bg-dark-700 shadow-lg ring-1 ring-white/10 focus:outline-none min-w-56', id]" >
21
+ <div v-if =" isSmallScreen" class =" w-full py-2" >
22
+ <div class =" rounded-full h-1 bg-gray-400 w-12 mx-auto" ></div >
23
+ </div >
24
+ <slot name =" items" ></slot >
25
+ </Menu .Content >
26
+ </transition >
27
+ </Menu .Positioner >
28
+ </Teleport >
25
29
</Menu .Root >
26
30
</template >
27
31
@@ -31,4 +35,32 @@ const { width } = useWindowSize();
31
35
const isSmallScreen = computed (() => width .value < 768 );
32
36
33
37
const open = ref (false );
38
+ const id = useId ();
39
+
40
+ // HACK: Fix the menu children not reacting to touch events as click for some reason
41
+ const registerClickHandlers = () => {
42
+ const targetElement = document .querySelector (` .${id } ` );
43
+ if (targetElement ) {
44
+ for (const el of targetElement .children ) {
45
+ el .addEventListener (" pointerdown" , (e ) => {
46
+ e .stopPropagation ();
47
+ e .preventDefault ();
48
+ // Click all element children
49
+ for (const elChild of Array .from (el .children )) {
50
+ if (elChild instanceof HTMLElement ) {
51
+ elChild .click ();
52
+ }
53
+ }
54
+ });
55
+ }
56
+ }
57
+ };
58
+
59
+ // When opening, register click handlers
60
+ watch (open , async (o ) => {
61
+ if (o ) {
62
+ await nextTick ();
63
+ registerClickHandlers ();
64
+ }
65
+ });
34
66
</script >
0 commit comments