A draggable sidebar component with width persistence and smooth transitions
Drag the right edge to resize
{ defaultWidth: 352, minWidth: 240, maxWidth: 480 }Drag the right edge to resize this sidebar. The width will be saved to localStorage.
Current Width:
352px
This area automatically adjusts as you resize the sidebar.
Custom min/max width constraints
{ defaultWidth: 280, minWidth: 200, maxWidth: 320 }Constrained between 200-320px
Width:
280px
Main content with a narrower sidebar
Combine with collapse functionality
{ collapsed: "boolean", defaultWidth: 352 }When collapsed, the resize handle disappears and the sidebar can show minimal content.
Click the button above to toggle the sidebar
Drag the left edge to resize
{ side: "right", defaultWidth: 352, minWidth: 240, maxWidth: 480 }This area automatically adjusts as you resize the right sidebar.
Drag the left edge to resize this sidebar. The resize handle appears on the left side.
Current Width:
352px
minWidth and maxWidth based on your content needsstorageKey for each instance to save widths separatelyonWidthChange callback to react to width changescollapsed={true} to hide resize handle and allow custom collapsed widthside="right" for right-aligned sidebars (resize handle on left edge)Import and Usage:
import { ResizableSidebar } from "@/components/ui/resizable-sidebar"
// Left sidebar (default)
<ResizableSidebar
defaultWidth={352}
minWidth={240}
maxWidth={480}
storageKey="my-sidebar"
onWidthChange={(width) => console.log(width)}
>
{/* Sidebar content */}
</ResizableSidebar>
// Right sidebar
<ResizableSidebar
side="right"
defaultWidth={352}
minWidth={240}
maxWidth={480}
storageKey="my-right-sidebar"
>
{/* Right sidebar content */}
</ResizableSidebar>| Prop | Type | Default | Description |
|---|---|---|---|
defaultWidth | number | 352 | Initial width of the sidebar |
minWidth | number | 240 | Minimum allowed width |
maxWidth | number | 480 | Maximum allowed width |
storageKey | string | "resizable-sidebar-width" | localStorage key for persisting width |
collapsed | boolean | false | Whether sidebar is collapsed |
onWidthChange | function | - | Callback when width changes |
side | "left" | "right" | "left" | Position of the sidebar (left or right) |
className | string | - | Additional CSS classes |