@devries-cameron20 / t3code-1 / commits / 780fb61a72
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): remove collapsed sidebar controls from keyboard navigation (#18849)

Co-authored-by: SAPHID <saphid@users.noreply.github.com> Co-authored-by: GPT-6.1 Sol <noreply@openai.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Alex Southwell committed Oct 20, 2026 at 08:10 UTC 780fb61a72dcbc17c13192e1d8fdb74b946ed88b
2 files changed +100 -2
apps/web/src/components/ui/sidebar.test.tsx
+81 -1
@@ -1,7 +1,55 @@
1 -import { describe, expect, it } from "vite-plus/test";
1 +// @vitest-environment jsdom
2
3 +import { act } from "react";
4 +import { createRoot, type Root } from "react-dom/client";
5 +import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
6 +
7 +import { Sidebar, SidebarProvider, SidebarTrigger } from "./sidebar";
8 import { resolveSidebarState } from "./sidebarState";
9
10 +let root: Root;
11 +let container: HTMLDivElement;
12 +
13 +beforeEach(() => {
14 + vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
15 + vi.stubGlobal("matchMedia", (query: string) => ({
16 + matches: false,
17 + media: query,
18 + addEventListener: vi.fn(),
19 + removeEventListener: vi.fn(),
20 + }));
21 + container = document.createElement("div");
22 + document.body.append(container);
23 + root = createRoot(container);
24 +});
25 +
26 +afterEach(async () => {
27 + await act(async () => root.unmount());
28 + container.remove();
29 + vi.unstubAllGlobals();
30 +});
31 +
32 +async function renderSidebar(open: boolean) {
33 + await act(async () => {
34 + root.render(
35 + <SidebarProvider open={open}>
36 + <Sidebar>
37 + <SidebarTrigger data-testid="internal-trigger" />
38 + <button data-testid="sidebar-control">Thread</button>
39 + </Sidebar>
40 + <SidebarTrigger data-testid="external-trigger" />
41 + <button data-testid="content-control">Content</button>
42 + </SidebarProvider>,
43 + );
44 + });
45 +}
46 +
47 +function element(selector: string) {
48 + const node = container.querySelector<HTMLElement>(selector);
49 + if (!node) throw new Error(`Missing element: ${selector}`);
50 + return node;
51 +}
52 +
53 describe("responsive sidebar state", () => {
54 it("uses mobile sheet visibility for the shared responsive state", () => {
55 expect(resolveSidebarState({ isMobile: true, open: true, openMobile: false })).toBe(
@@ -13,3 +61,35 @@ describe("responsive sidebar state", () => {
61 );
62 });
63 });
64 +
65 +describe("desktop sidebar focus", () => {
66 + it("moves focus to the external toggle on collapse and restores sidebar access on expansion", async () => {
67 + await renderSidebar(true);
68 + const control = element('[data-testid="sidebar-control"]');
69 + const sidebar = element('[data-slot="sidebar"]');
70 + control.focus();
71 + expect(document.activeElement).toBe(control);
72 +
73 + await renderSidebar(false);
74 +
75 + expect(document.activeElement).toBe(element('[data-testid="external-trigger"]'));
76 + expect(sidebar.hasAttribute("inert")).toBe(true);
77 +
78 + await renderSidebar(true);
79 +
80 + expect(sidebar.hasAttribute("inert")).toBe(false);
81 + control.focus();
82 + expect(document.activeElement).toBe(control);
83 + });
84 +
85 + it("keeps focus in the content when the sidebar collapses", async () => {
86 + await renderSidebar(true);
87 + const control = element('[data-testid="content-control"]');
88 + control.focus();
89 + expect(document.activeElement).toBe(control);
90 +
91 + await renderSidebar(false);
92 +
93 + expect(document.activeElement).toBe(control);
94 + });
95 +});
apps/web/src/components/ui/sidebar.tsx
+19 -1
@@ -215,7 +215,24 @@ function Sidebar({
215 resizable?: boolean | SidebarResizableOptions;
216 }) {
217 const { isMobile, state, openMobile, setOpenMobile, setMobileSheetElement } = useSidebar();
218 - // The rail's width restore and drag refresh key on this value.
218 + const desktopSidebarRef = React.useRef<HTMLDivElement>(null);
219 + const offcanvasCollapsed = !isMobile && collapsible === "offcanvas" && state === "collapsed";
220 +
221 + React.useLayoutEffect(() => {
222 + const sidebar = desktopSidebarRef.current;
223 + if (!sidebar) return;
224 +
225 + // Transfer focus before inert causes the browser to clear the focused descendant.
226 + if (offcanvasCollapsed && sidebar.contains(document.activeElement)) {
227 + const wrapper = sidebar.closest('[data-slot="sidebar-wrapper"]');
228 + const trigger = Array.from(
229 + wrapper?.querySelectorAll<HTMLElement>('[data-sidebar="trigger"]') ?? [],
230 + ).find((element) => !sidebar.contains(element));
231 + trigger?.focus({ preventScroll: true });
232 + }
233 + sidebar.toggleAttribute("inert", offcanvasCollapsed);
234 + }, [offcanvasCollapsed]);
235 +
236 const resolvedResizable = resolveSidebarResizable({ collapsible, isMobile, resizable });
237 const instanceContextValue: SidebarInstanceContextProps = { side, resizable: resolvedResizable };
238
@@ -280,6 +297,7 @@ function Sidebar({
297 return (
298 <SidebarInstanceContext value={instanceContextValue}>
299 <div
300 + ref={desktopSidebarRef}
301 className="group peer hidden text-sidebar-foreground md:block"
302 data-collapsible={state === "collapsed" ? collapsible : ""}
303 data-side={side}