Skip to content

Commit 63d8f4f

Browse files
committed
fix: collapse Brain sidebar sub-menu when navigating away from Brain page
Switch Brain Collapsible from uncontrolled defaultOpen to controlled open prop derived from activeView, so the sub-menu only expands on Brain pages.
1 parent 69d443a commit 63d8f4f

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

apps/desktop/src/app/shell/AppSidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export function AppSidebar({
238238

239239
{/* Brain — collapsible */}
240240
<Collapsible
241-
defaultOpen={activeView === "brain"}
241+
open={activeView === "brain"}
242242
asChild
243243
className="group/collapsible"
244244
>

test/ui/sidebar-brain-subnav.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,16 @@ describe("Sidebar Brain sub-navigation", () => {
6868
// The sidebar should use sidebar- prefixed tokens which adapt to theme
6969
expect(sidebarSrc).toMatch(/sidebar-accent|sidebar-foreground|sidebar-primary/);
7070
});
71+
72+
// AC6: Brain sub-menu collapses when navigating away from Brain page
73+
it("uses controlled open prop derived from activeView, not defaultOpen", () => {
74+
// The Collapsible wrapping the Brain section must use the controlled `open`
75+
// prop so that expand/collapse state tracks the current route, collapsing
76+
// when the user navigates away from Brain pages.
77+
// It should NOT use defaultOpen (which only sets initial state and then
78+
// Radix manages it internally, causing the menu to stay open on all pages).
79+
expect(sidebarSrc).toMatch(/open=\{activeView\s*===\s*["']brain["']\}/);
80+
// Ensure defaultOpen is NOT used for the Brain collapsible
81+
expect(sidebarSrc).not.toMatch(/defaultOpen=\{activeView\s*===\s*["']brain["']\}/);
82+
});
7183
});

0 commit comments

Comments
 (0)