Skip to content

Commit 7fe5dbc

Browse files
authored
fix: persist left/right sidebar open state (#231)
Replace the single STORAGE_KEY with separate LEFT_KEY and RIGHT_KEY constants and compute a defaultOpen object from localStorage for each side. Pass storageKey as an object ({ left, right }) and defaultOpen to SidebarProvider so left and right sidebars persist their expanded/collapsed state independently (any value other than 'false' is treated as open).
1 parent a1c7166 commit 7fe5dbc

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/components/Sidebar/Sidebar.stories.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,20 @@ export const SidebarBothSides = () => {
238238
const [activeTeam, setActiveTeam] = React.useState(data.teams[0]);
239239
const isMobile = useIsMobile();
240240

241-
const STORAGE_KEY = 'sidebar_dual_expanded_storybook';
241+
const RIGHT_KEY = 'sidebar_dual_expanded_storybook_right';
242+
const LEFT_KEY = 'sidebar_dual_expanded_storybook_left';
243+
244+
const defaultOpen = {
245+
left: localStorage.getItem(LEFT_KEY) !== 'false',
246+
right: localStorage.getItem(RIGHT_KEY) !== 'false',
247+
};
242248

243249
return (
244250
<ResponsiveProvider>
245-
<SidebarProvider storageKey={STORAGE_KEY} defaultOpen>
251+
<SidebarProvider
252+
storageKey={{ left: LEFT_KEY, right: RIGHT_KEY }}
253+
defaultOpen={defaultOpen}
254+
>
246255
<Sidebar side="left" collapsible="icon">
247256
<NavHeader activeTeam={activeTeam} setActiveTeam={setActiveTeam} />
248257
<SidebarContent>

0 commit comments

Comments
 (0)