@@ -109,13 +109,24 @@ export const VMenu = genericComponent<OverlaySlots>()({
109
109
} )
110
110
onDeactivated ( ( ) => isActive . value = false )
111
111
112
+ let focusTrapSuppressed = false
113
+ let focusTrapSuppressionTimeout = - 1
114
+
115
+ async function onPointerdown ( ) {
116
+ focusTrapSuppressed = true
117
+ focusTrapSuppressionTimeout = window . setTimeout ( ( ) => {
118
+ focusTrapSuppressed = false
119
+ } , 100 )
120
+ }
121
+
112
122
async function onFocusIn ( e : FocusEvent ) {
113
123
const before = e . relatedTarget as HTMLElement | null
114
124
const after = e . target as HTMLElement | null
115
125
116
126
await nextTick ( )
117
127
118
128
if (
129
+ ! focusTrapSuppressed &&
119
130
isActive . value &&
120
131
before !== after &&
121
132
overlay . value ?. contentEl &&
@@ -128,18 +139,23 @@ export const VMenu = genericComponent<OverlaySlots>()({
128
139
) {
129
140
const focusable = focusableChildren ( overlay . value . contentEl )
130
141
focusable [ 0 ] ?. focus ( )
142
+
143
+ document . removeEventListener ( 'pointerdown' , onPointerdown )
131
144
}
132
145
}
133
146
134
147
watch ( isActive , val => {
135
148
if ( val ) {
136
149
parent ?. register ( )
137
150
if ( IN_BROWSER && ! props . disableInitialFocus ) {
151
+ document . addEventListener ( 'pointerdown' , onPointerdown )
138
152
document . addEventListener ( 'focusin' , onFocusIn , { once : true } )
139
153
}
140
154
} else {
141
155
parent ?. unregister ( )
142
156
if ( IN_BROWSER ) {
157
+ clearTimeout ( focusTrapSuppressionTimeout )
158
+ document . removeEventListener ( 'pointerdown' , onPointerdown )
143
159
document . removeEventListener ( 'focusin' , onFocusIn )
144
160
}
145
161
}
0 commit comments