The best way to control Claude Code, Codex and more from any computer or phone
fix(web): keyboard-opened sidebar menus select their first item (#37727)
Julius Marminge committed
Nov 16, 2026 at 10:43 UTC
1d1489d0b8e7448b7f020fc9a6325f593caf147e
6 files changed
+94
-14
apps/web/src/components/Sidebar.browser.test.tsx
+42
@@ -6,6 +6,7 @@ import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell
6
import {
7
DEFAULT_CLIENT_SETTINGS,
8
EnvironmentId,
9
+ type LocalApi,
10
ProjectId,
11
ThreadId,
12
type ScopedThreadRef,
@@ -25,6 +26,7 @@ import { useProjects, useServerConfigs, useQuietThreadShells } from "../state/en
26
import { readEnvironmentScope, useEnvironmentScope } from "../state/session";
27
import { useOrchestrationCommand } from "../state/use-orchestration-command";
28
import { useTerminalUiStateStore } from "../terminalUiStateStore";
29
+import { readLocalApi } from "../localApi";
30
import type { Project } from "../types";
31
import Sidebar from "./Sidebar";
32
import { THREAD_JUMP_HINT_SHOW_DELAY_MS } from "./Sidebar.logic";
@@ -42,6 +44,7 @@ vi.mock("../hooks/useThreadRouteTarget", { spy: true });
44
vi.mock("./sidebar/SidebarThreadRow", { spy: true });
45
vi.mock("../state/session", { spy: true });
46
vi.mock("../state/use-orchestration-command", { spy: true });
47
+vi.mock("../localApi", { spy: true });
48
vi.mock(import("../state/server"), async (original) => {
49
const { Atom } = await import("effect/reactivity");
50
const { compileResolvedKeybindingsConfig } = await import("@t3tools/shared/keybindings");
@@ -261,6 +264,45 @@ describe("sidebar thread rename", () => {
264
);
265
});
266
267
+describe("sidebar thread menu", () => {
268
+ it("tells the menu whether the keyboard opened it", async () => {
269
+ const activeProject = project("active");
270
+ const thread = threadShell(activeProject.id, 0);
271
+ const threadRef = { environmentId: activeProject.environmentId, threadId: thread.id };
272
+ const show = vi.fn().mockResolvedValue(null);
273
+ vi.mocked(readLocalApi).mockReturnValue({ contextMenu: { show } } as unknown as LocalApi);
274
+ vi.mocked(useProjects).mockReturnValue([activeProject]);
275
+ vi.mocked(useQuietThreadShells).mockReturnValue([thread]);
276
+ vi.mocked(useThreadRouteTarget).mockReturnValue({ kind: "server", threadRef });
277
+ vi.mocked(useHandleNewThread).mockReturnValue({
278
+ activeDraftThread: null,
279
+ activeThread: null,
280
+ defaultProjectRef: {
281
+ environmentId: activeProject.environmentId,
282
+ projectId: activeProject.id,
283
+ },
284
+ defaultProjectFallbackReady: true,
285
+ handleNewThread: vi.fn().mockResolvedValue(null),
286
+ routeDraftId: null,
287
+ routeThreadRef: threadRef,
288
+ });
289
+ await using screen = await render(
290
+ <SidebarProvider>
291
+ <Sidebar routeReveal={{ observedKey: null, pendingKey: null }} />
292
+ </SidebarProvider>,
293
+ );
294
+ const row = screen.getByText("Thread 0").first();
295
+ await expect.element(row).toBeInTheDocument();
296
+ row.element().closest<HTMLElement>("[data-sidebar-row]")!.focus();
297
+ await userEvent.keyboard("{Shift>}{F10}{/Shift}");
298
+ await vi.waitFor(() => expect(show).toHaveBeenCalledTimes(1));
299
+ expect(show.mock.lastCall?.[2]).toBe("keyboard");
300
+ await userEvent.click(row, { button: "right" });
301
+ await vi.waitFor(() => expect(show).toHaveBeenCalledTimes(2));
302
+ expect(show.mock.lastCall?.[2]).toBe("mouse");
303
+ });
304
+});
305
+
306
describe("sidebar settled pagination", () => {
307
it("keeps the viewport in place when showing more settled threads", async () => {
308
using stack = new DisposableStack();
apps/web/src/components/Sidebar.tsx
+14
-5
@@ -55,6 +55,7 @@ import {
55
} from "@t3tools/client-runtime/environment";
56
import {
57
AuthOrchestrationOperateScope,
58
+ type ContextMenuSource,
59
ProjectId,
60
type ScopedThreadRef,
61
type ThreadId,
@@ -1250,7 +1251,11 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
1251
void handleNewThread(scopeProjectRef(group.environmentId, group.id));
1252
});
1253
const handleProjectFolderContextMenu = useStableCallback(
1253
- (group: SidebarProjectSnapshot, position: { x: number; y: number }) => {
1254
+ (
1255
+ group: SidebarProjectSnapshot,
1256
+ position: { x: number; y: number },
1257
+ source: ContextMenuSource,
1258
+ ) => {
1259
const api = readLocalApi();
1260
if (!api) return;
1261
void (async () => {
@@ -1269,6 +1274,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
1274
{ id: "project-settings", label: "Project settings", icon: "settings" },
1275
],
1276
position,
1277
+ source,
1278
),
1279
);
1280
if (clicked._tag === "Failure") return;
@@ -2283,7 +2289,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2289
);
2290
2291
const handleMultiSelectContextMenu = useStableCallback(
2286
- async (position: { x: number; y: number }) => {
2292
+ async (position: { x: number; y: number }, source: ContextMenuSource) => {
2293
const api = readLocalApi();
2294
if (!api) return;
2295
const selectedThreadKeys = [...useThreadSelectionStore.getState().selectedThreadKeys];
@@ -2381,6 +2387,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2387
},
2388
],
2389
position,
2390
+ source,
2391
),
2392
);
2393
if (clicked._tag === "Failure" || clicked.value === null) return;
@@ -2534,7 +2541,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2541
);
2542
2543
const handleDraftContextMenu = useStableCallback(
2537
- (draftId: DraftId, position: { x: number; y: number }) => {
2544
+ (draftId: DraftId, position: { x: number; y: number }, source: ContextMenuSource) => {
2545
void (async () => {
2546
const api = readLocalApi();
2547
const session = useComposerDraftStore.getState().getDraftSession(draftId);
@@ -2556,6 +2563,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2563
hasProject: projectGroup != null,
2564
}),
2565
position,
2566
+ source,
2567
),
2568
);
2569
if (clicked._tag === "Failure") return;
@@ -2585,14 +2593,14 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2593
);
2594
2595
const handleThreadContextMenu = useStableCallback(
2588
- (threadRef: ScopedThreadRef, position: { x: number; y: number }) => {
2596
+ (threadRef: ScopedThreadRef, position: { x: number; y: number }, source: ContextMenuSource) => {
2597
void (async () => {
2598
const api = readLocalApi();
2599
if (!api) return;
2600
const threadKey = scopedThreadKey(threadRef);
2601
const selectionState = useThreadSelectionStore.getState();
2602
if (selectionState.hasSelection() && selectionState.selectedThreadKeys.has(threadKey)) {
2595
- await handleMultiSelectContextMenu(position);
2603
+ await handleMultiSelectContextMenu(position, source);
2604
return;
2605
}
2606
const thread = threadByKeyRef.current.get(threadKey);
@@ -2659,6 +2667,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2667
snoozePresets,
2668
}),
2669
position,
2670
+ source,
2671
),
2672
);
2673
if (clicked._tag === "Failure" || clicked.value === null) return;
apps/web/src/components/sidebar/SidebarDraftBlock.tsx
+14
-4
@@ -1,4 +1,6 @@
1
import { discardComposerDraft } from "../../lib/discardComposerDraft";
2
+import type { ContextMenuSource } from "@t3tools/contracts";
3
+import { contextMenuSourceOf } from "../../contextMenuSource";
4
import { assistantCitationsToPlainText } from "@t3tools/shared/assistantCitations";
5
import { replaceComposerContextReferences } from "@t3tools/shared/composerContextReferences";
6
import { SquarePenIcon, XIcon } from "lucide-react";
@@ -31,7 +33,11 @@ const SidebarDraftRow = memo(function SidebarDraftRow(props: {
33
isActive: boolean;
34
onNavigate: (draftId: DraftId) => void;
35
onDiscard: (draftId: DraftId) => void;
34
- onContextMenu: (draftId: DraftId, position: { x: number; y: number }) => void;
36
+ onContextMenu: (
37
+ draftId: DraftId,
38
+ position: { x: number; y: number },
39
+ source: ContextMenuSource,
40
+ ) => void;
41
}) {
42
const { composer, draftId, onContextMenu, onDiscard, onNavigate } = props;
43
const promptPreview =
@@ -67,7 +73,7 @@ const SidebarDraftRow = memo(function SidebarDraftRow(props: {
73
if (event.key === "ContextMenu" || (event.shiftKey && event.key === "F10")) {
74
event.preventDefault();
75
const rect = event.currentTarget.getBoundingClientRect();
70
- onContextMenu(draftId, { x: rect.left, y: rect.bottom });
76
+ onContextMenu(draftId, { x: rect.left, y: rect.bottom }, "keyboard");
77
} else if (event.key === "Enter" || event.key === " ") {
78
event.preventDefault();
79
onNavigate(draftId);
@@ -75,7 +81,7 @@ const SidebarDraftRow = memo(function SidebarDraftRow(props: {
81
};
82
const handleContextMenu = (event: ReactMouseEvent) => {
83
event.preventDefault();
78
- onContextMenu(draftId, { x: event.clientX, y: event.clientY });
84
+ onContextMenu(draftId, { x: event.clientX, y: event.clientY }, contextMenuSourceOf(event));
85
};
86
const handleDiscard = (event: ReactMouseEvent) => {
87
event.preventDefault();
@@ -145,7 +151,11 @@ export const SidebarDraftBlock = memo(function SidebarDraftBlock(props: {
151
scopedProjectKeys: ReadonlySet<string> | null;
152
routeDraftId: string | null;
153
onNavigateToDraft: (draftId: DraftId) => void;
148
- onDraftContextMenu: (draftId: DraftId, position: { x: number; y: number }) => void;
154
+ onDraftContextMenu: (
155
+ draftId: DraftId,
156
+ position: { x: number; y: number },
157
+ source: ContextMenuSource,
158
+ ) => void;
159
}) {
160
const draftThreadsByThreadKey = useComposerDraftStore((store) => store.draftThreadsByThreadKey);
161
const draftsByThreadKey = useComposerDraftStore(
apps/web/src/components/sidebar/SidebarProjectFolderHeader.tsx
+12
-2
@@ -1,9 +1,11 @@
1
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/models";
2
import { scopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime/environment";
3
+import type { ContextMenuSource } from "@t3tools/contracts";
4
import { ChevronDownIcon, SquarePenIcon } from "lucide-react";
5
import { memo } from "react";
6
7
import { cn } from "~/lib/utils";
8
+import { contextMenuSourceOf } from "../../contextMenuSource";
9
import type { SidebarProjectSnapshot } from "../../sidebarProjectGrouping";
10
import { useUiStateStore } from "../../uiStateStore";
11
import { resolveSidebarFolderDot, resolveThreadLastVisitedAt } from "../Sidebar.logic";
@@ -41,7 +43,11 @@ export const SidebarProjectFolderHeader = memo(function SidebarProjectFolderHead
43
hiddenThreads: readonly EnvironmentThreadShell[];
44
onToggle: (group: SidebarProjectSnapshot) => void;
45
onNewThread: (group: SidebarProjectSnapshot) => void;
44
- onContextMenu: (group: SidebarProjectSnapshot, position: { x: number; y: number }) => void;
46
+ onContextMenu: (
47
+ group: SidebarProjectSnapshot,
48
+ position: { x: number; y: number },
49
+ source: ContextMenuSource,
50
+ ) => void;
51
}) {
52
const { group, collapsed, hiddenThreads } = props;
53
const rowId = sidebarFolderRowId(group.projectKey);
@@ -71,7 +77,11 @@ export const SidebarProjectFolderHeader = memo(function SidebarProjectFolderHead
77
onClick={() => props.onToggle(group)}
78
onContextMenu={(event) => {
79
event.preventDefault();
74
- props.onContextMenu(group, { x: event.clientX, y: event.clientY });
80
+ props.onContextMenu(
81
+ group,
82
+ { x: event.clientX, y: event.clientY },
83
+ contextMenuSourceOf(event),
84
+ );
85
}}
86
className="flex h-8 w-full cursor-pointer items-center gap-2.5 rounded-(--control-radius) px-(--sidebar-row-content-inset) text-left outline-none hover:bg-sidebar-row-hover focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
87
>
apps/web/src/components/sidebar/SidebarThreadRow.tsx
+8
-2
@@ -3,6 +3,7 @@ import { asLaunchingThread } from "@t3tools/client-runtime/state/thread-inbox";
3
import { ThreadHoverCard, ThreadHoverCardPopup } from "../ThreadHoverCard";
4
import { ThreadTerminalStatusButton } from "../ThreadStatusIndicators";
5
import { discardComposerDraft } from "../../lib/discardComposerDraft";
6
+import { contextMenuSourceOf } from "../../contextMenuSource";
7
import { requestCustomSnooze } from "../CustomSnoozeDialog";
8
import { useSupportsMultiplePullRequests } from "~/hooks/useSupportsMultiplePullRequests";
9
import { useDeadlinePassed } from "~/hooks/useDeadline";
@@ -29,6 +30,7 @@ import { scopeThreadRef, scopedThreadKey } from "@t3tools/client-runtime/environ
30
import { toServerClock } from "@t3tools/client-runtime/clock";
31
import {
32
AuthOrchestrationOperateScope,
33
+ type ContextMenuSource,
34
type EnvironmentId,
35
type EnvironmentMachineKind,
36
type ScopedThreadRef,
@@ -587,7 +589,11 @@ type SidebarThreadRowProps = {
589
onCancelRename: () => void;
590
isRenaming: boolean;
591
renamingTitle: string;
590
- onContextMenu: (threadRef: ScopedThreadRef, position: { x: number; y: number }) => void;
592
+ onContextMenu: (
593
+ threadRef: ScopedThreadRef,
594
+ position: { x: number; y: number },
595
+ source: ContextMenuSource,
596
+ ) => void;
597
onSettle: (threadRef: ScopedThreadRef) => void;
598
onActionSweepStart: (
599
threadRef: ScopedThreadRef,
@@ -861,7 +867,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
867
};
868
const handleContextMenu = (event: ReactMouseEvent) => {
869
event.preventDefault();
864
- onContextMenu(threadRef, { x: event.clientX, y: event.clientY });
870
+ onContextMenu(threadRef, { x: event.clientX, y: event.clientY }, contextMenuSourceOf(event));
871
};
872
const handleKeyDown = (event: ReactKeyboardEvent) => {
873
if (event.target !== event.currentTarget) return;
apps/web/src/lib/sidebarTree.ts
+4
-1
@@ -155,9 +155,12 @@ export function installSidebarTree(root: HTMLElement) {
155
// Like VS Code's list, suppress keydown and open on release. Reuse the row's
156
// selection-aware handler, including its Electron native menu route.
157
row.dispatchEvent(
158
- new MouseEvent("contextmenu", {
158
+ // A PointerEvent, as Chromium sends, keeps button -1 (a MouseEvent clamps it to 0),
159
+ // which contextMenuSourceOf reads as a keyboard-opened menu.
160
+ new PointerEvent("contextmenu", {
161
bubbles: true,
162
cancelable: true,
163
+ button: -1,
164
clientX: rect.left,
165
clientY: rect.bottom,
166
}),