File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -196,6 +196,23 @@ describe("showContextMenuFallback", () => {
196196 await expect ( selectionPromise ) . resolves . toBe ( "rename" ) ;
197197 } ) ;
198198
199+ it ( "ignores a click from the gesture that opened the menu" , async ( ) => {
200+ let enablePointerSelection : ( ( time : number ) => void ) | undefined ;
201+ vi . stubGlobal ( "requestAnimationFrame" , ( callback : ( time : number ) => void ) => {
202+ enablePointerSelection = callback ;
203+ return 0 ;
204+ } ) ;
205+
206+ const selectionPromise = showContextMenuFallback ( [ { id : "rename" , label : "Rename" } ] ) ;
207+ const renameButton = findButton ( "Rename" ) ;
208+
209+ renameButton ?. dispatchEvent ( new MouseEvent ( "click" , { bubbles : true } ) ) ;
210+ enablePointerSelection ?.( 0 ) ;
211+ renameButton ?. dispatchEvent ( new MouseEvent ( "click" , { bubbles : true } ) ) ;
212+
213+ await expect ( selectionPromise ) . resolves . toBe ( "rename" ) ;
214+ } ) ;
215+
199216 it ( "opens nested submenus and resolves the clicked leaf id" , async ( ) => {
200217 const selectionPromise = showContextMenuFallback ( [
201218 {
Original file line number Diff line number Diff line change @@ -272,7 +272,9 @@ export function showContextMenuFallback<T extends string>(
272272 button . addEventListener ( "mouseenter" , ( ) => {
273273 closeMenusFromLevel ( level + 1 ) ;
274274 } ) ;
275- button . addEventListener ( "click" , ( ) => cleanup ( item . id ) ) ;
275+ button . addEventListener ( "click" , ( ) => {
276+ if ( canDismissFromPointer ) cleanup ( item . id ) ;
277+ } ) ;
276278 }
277279 }
278280
You can’t perform that action at this time.
0 commit comments