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