Skip to content

Commit 993d754

Browse files
committed
docs: address PR review feedback on Sidebar docs
- Scope the docs-page iframe CSS to this page's Canvas blocks via parameters.docs.canvas.className instead of targeting .sbdocs-content globally - Add an SSR guard to the localStorage read in the state persistence example so it is safe to copy into Next.js apps Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01785n4jaUDCkRNRLpbG9dz6
1 parent 293b10d commit 993d754

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

packages/components/src/components/Sidebar/Sidebar.mdx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import * as Stories from './Sidebar.stories';
1313
The embedded stories render in iframes, and the iframe is the story's
1414
viewport. Keep it at least as wide as the desktop breakpoint (992px) so
1515
the examples show the desktop sidebar instead of the mobile drawer,
16-
scrolling horizontally when the docs column is narrower.
16+
scrolling horizontally when the docs column is narrower. Scoped to this
17+
page's Canvas blocks via the sidebar-docs-canvas class.
1718
*/}
1819

1920
<style>
2021
{`
21-
.sbdocs-content .docs-story { overflow-x: auto; }
22-
.sbdocs-content .docs-story iframe { min-width: 1100px; }
22+
.sidebar-docs-canvas .docs-story { overflow-x: auto; }
23+
.sidebar-docs-canvas .docs-story iframe { min-width: 1100px; }
2324
`}
2425
</style>
2526

@@ -126,7 +127,12 @@ Pass `defaultOpen={false}` to the provider to start collapsed.
126127
Whenever the user toggles a sidebar, the provider writes the new state to `localStorage` under the resolved `storageKey` (a string key applies to the left sidebar, with `_right` appended for the right sidebar; pass an object to set each side explicitly). Reading the stored value back is left to your app — pass it to `defaultOpen` on mount:
127128

128129
```tsx
129-
const startExpanded = localStorage.getItem('sidebar_expanded') !== 'false';
130+
// Guard the read so it is safe in SSR environments (e.g. Next.js),
131+
// where localStorage does not exist on the server.
132+
const startExpanded =
133+
typeof window !== 'undefined'
134+
? localStorage.getItem('sidebar_expanded') !== 'false'
135+
: true;
130136

131137
<SidebarProvider storageKey="sidebar_expanded" defaultOpen={startExpanded}>
132138
...

packages/components/src/components/Sidebar/Sidebar.stories.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ const meta: Meta<typeof Sidebar> = {
5757
inline: false,
5858
height: '640px',
5959
},
60+
// Scopes the docs-page CSS in Sidebar.mdx (which forces a desktop-width
61+
// viewport on the story iframes) to this page's Canvas blocks only.
62+
canvas: {
63+
className: 'sidebar-docs-canvas',
64+
},
6065
},
6166
chromatic: {
6267
modes: {

0 commit comments

Comments
 (0)