A Sidebar is the frame around a Nav: it owns the width, the collapse, the resize handle and the phone drawer, so the Nav inside only has to say what the rows are. Drag its edge to resize it. Drag past the minimum and it folds into an icon rail; drag the rail out and it opens again. Double-click the edge to reset it. ⌘B (Ctrl+B elsewhere) folds it from anywhere outside a text field.
- Sidebar is the frame: an aside that holds the width and draws the handle on its edge.
- SidebarHeader and SidebarFooter stay put. Put the workspace switcher on top and the account at the bottom. In the rail they clip to their leading mark rather than wrap.
- SidebarContent takes the space left and scrolls on its own. It holds the Nav.
- SidebarTrigger folds and unfolds it, or opens the drawer on a phone. Its tooltip names the shortcut. Put it in the top bar or in the SidebarHeader.
- SidebarProvider holds the state for the Sidebar and for anything outside it that reads or changes it: the trigger in the top bar, ⌘B, useSidebar(). A Sidebar with no provider around it makes its own.
Give the provider a persist key and it keeps the width and the collapse in a cookie. Read the cookie on the server and pass it back as the defaults, and the first paint is already right: no default width that jumps once the browser has looked.
Both helpers are plain functions, safe to call in a server component and outside Next.js: read the cookie however your framework does and pass its value to parseSidebarCookie.
With expandOnHover, a mouse resting on the rail opens it over the page, labels and all, and the page beside it does not move. Keyboard focus opens it too; Escape or leaving closes it. Touch never opens it.
In the rail, a NavGroup is its icon, and a click opens its rows in a menu beside it.
collapsible="offcanvas" slides it out entirely instead of leaving a rail, for a chat list or a file tree that has no icons to keep. While it is out, nothing in it can be reached by Tab. collapsible={false} keeps it open.
Below mobileBelow (default s) the sidebar is a drawer from the left, with the same children at full labels. The SidebarTrigger opens it, and following a link inside closes it. mobileBelow={false} keeps the desktop sidebar at every width.
The edge is a focusable separator with its width as its value.
The width eases between open, rail and hidden on the macro transition, and the Nav's labels fade on the micro one. Nothing animates while you drag, and with prefers-reduced-motion nothing animates at all.