The best way to control Claude Code, Codex and more from any computer or phone
fix(web): file context menu actions respond to pointer clicks (#26579)
Co-authored-by: Dan Bolser <dan.bolser@outsee.co.uk> Co-authored-by: maria-rcks <maria@kuuro.net>
Dan B committed
Oct 31, 2026 at 01:41 UTC
461df465abeeef3ff0359fb0c4da4d987286115e
3 files changed
+46
-3
apps/web/src/components/files/FileBrowserPanel.browser.test.tsx
+39
@@ -1,7 +1,9 @@
1
import { EnvironmentId, type ProjectEntry } from "@t3tools/contracts";
2
import { describe, expect, it, vi } from "vite-plus/test";
3
+import { page, userEvent } from "vite-plus/test/browser";
4
5
import { COMPOSER_MENTION_DRAG_TYPE } from "~/components/chat/composerMentionDrag";
6
+import { dismissContextMenu } from "~/contextMenuFallback";
7
import { render } from "../../../test/render";
8
import FileBrowserPanel from "./FileBrowserPanel";
9
@@ -43,6 +45,43 @@ function findTreeRow(path: string): HTMLElement | null {
45
}
46
47
describe("FileBrowserPanel", () => {
48
+ it("copies with the pointer and returns to the row after keyboard dismissal", async () => {
49
+ await using _screen = await render(
50
+ <FileBrowserPanel
51
+ environmentId={EnvironmentId.make("env-files")}
52
+ cwd="/repo"
53
+ projectName="repo"
54
+ selectedPath={null}
55
+ selectedPathRevealId={0}
56
+ onOpenFile={() => {}}
57
+ workspaceMutationId={null}
58
+ />,
59
+ );
60
+ using _menu = { [Symbol.dispose]: () => dismissContextMenu() };
61
+ using clipboard = vi.spyOn(navigator.clipboard, "writeText").mockResolvedValue(undefined);
62
+ await vi.waitFor(() => expect(findTreeRow("README.md")).not.toBeNull());
63
+ findTreeRow("README.md")!.dispatchEvent(
64
+ new MouseEvent("contextmenu", {
65
+ bubbles: true,
66
+ cancelable: true,
67
+ composed: true,
68
+ button: 2,
69
+ }),
70
+ );
71
+ const action = page.getByRole("menuitem", { name: "Copy mention", exact: true });
72
+ await expect.element(action).toBeVisible();
73
+ await userEvent.click(action);
74
+ await vi.waitFor(() => expect(clipboard).toHaveBeenCalledWith("[README.md](README.md)"));
75
+
76
+ const row = findTreeRow("README.md")!;
77
+ await userEvent.keyboard("{Tab}");
78
+ row.focus();
79
+ await userEvent.keyboard("{Shift>}{F10}{/Shift}");
80
+ await expect.element(action).toHaveFocus();
81
+ await userEvent.keyboard("{Escape}");
82
+ await vi.waitFor(() => expect((row.getRootNode() as ShadowRoot).activeElement).toBe(row));
83
+ });
84
+
85
it("dragging a file row carries a composer mention without opening it, and dragend releases it", async () => {
86
const onOpenFile = vi.fn();
87
await using _screen = await render(
apps/web/src/components/files/FileBrowserPanel.tsx
+2
-1
@@ -192,6 +192,8 @@ export default function FileBrowserPanel({
192
: { x: anchorRect.left, y: anchorRect.bottom };
193
const fileTarget = { environmentId, filePath: relativePath, workspaceRoot: cwd };
194
const fileMenuItems = fileContextMenu.buildItems(fileTarget);
195
+ // The app menu owns focus; the tree's outside-click handler would dismiss it before click.
196
+ context.close({ restoreFocus: !pointerIsFresh });
197
void settlePromise(async () => {
198
const clicked = await api.contextMenu.show(
199
[
@@ -246,7 +248,6 @@ export default function FileBrowserPanel({
248
}
249
}
250
}).then((result) => {
249
- context.close();
251
if (!AsyncResult.isSuccess(result)) throw Cause.squash(result.cause);
252
});
253
},
apps/web/src/contextMenuFallback.ts
+5
-2
@@ -245,8 +245,11 @@ export function showContextMenuFallback<T extends string>(
245
): Promise<T | null> {
246
dismissContextMenu();
247
return new Promise<T | null>((resolve) => {
248
- const previouslyFocusedElement =
249
- document.activeElement instanceof HTMLElement ? document.activeElement : null;
248
+ let focusedElement = document.activeElement;
249
+ while (focusedElement?.shadowRoot?.activeElement) {
250
+ focusedElement = focusedElement.shadowRoot.activeElement;
251
+ }
252
+ const previouslyFocusedElement = focusedElement instanceof HTMLElement ? focusedElement : null;
253
const menuStack: HTMLDivElement[] = [];
254
const submenuTriggerStack: Array<HTMLButtonElement | undefined> = [];
255
let isDisposed = false;