fix: prevent initial right-click from selecting a context menu item (#3877)

This commit is contained in:
Fazal Kadivar authored and GitHub committed 2026-07-17 21:42:13 +02:00
1 parent a7f6d97b94
commit e057e2e985
2 files changed
+20 -1

No files matched your search

+17
View File
@@ -196,6 +196,23 @@ describe("showContextMenuFallback", () => {
await expect(selectionPromise).resolves.toBe("rename");
});
it("ignores a click from the gesture that opened the menu", async () => {
let enablePointerSelection: ((time: number) => void) | undefined;
vi.stubGlobal("requestAnimationFrame", (callback: (time: number) => void) => {
enablePointerSelection = callback;
return 0;
});
const selectionPromise = showContextMenuFallback([{ id: "rename", label: "Rename" }]);
const renameButton = findButton("Rename");
renameButton?.dispatchEvent(new MouseEvent("click", { bubbles: true }));
enablePointerSelection?.(0);
renameButton?.dispatchEvent(new MouseEvent("click", { bubbles: true }));
await expect(selectionPromise).resolves.toBe("rename");
});
it("opens nested submenus and resolves the clicked leaf id", async () => {
const selectionPromise = showContextMenuFallback([
{
+3 -1
View File
@@ -272,7 +272,9 @@ export function showContextMenuFallback<T extends string>(
button.addEventListener("mouseenter", () => {
closeMenusFromLevel(level + 1);
});
button.addEventListener("click", () => cleanup(item.id));
button.addEventListener("click", () => {
if (canDismissFromPointer) cleanup(item.id);
});
}
}