Components
Resizable Sidebar
A sidebar you can drag wider or narrower.
Drag the edge, or focus it and use the arrow keys.
<ResizableSidebar label="Files">
<FileTree />
</ResizableSidebar>Installation
npx shadcn@latest add https://ui.zjkm.tech/r/resizable-sidebar.jsonimport { ResizableSidebar } from "@/components/resizable-sidebar"Using JavaScript? Set tsx: false in components.json and the CLI converts it.
New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.
Usage
A sidebar you can drag wider or narrower. The edge is a focusable separator, so arrow keys resize it too (hold Shift for big steps), and Home and End jump to the narrowest and widest.
import { ResizableSidebar } from "@/components/resizable-sidebar";
export function Layout({ children }: { children: React.ReactNode }) {
return (
<div className="flex h-screen">
<ResizableSidebar label="Files" onResize={(w) => localStorage.setItem("sidebar", String(w))}>
<FileTree />
</ResizableSidebar>
<main className="flex-1">{children}</main>
</div>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | The sidebar's content. | |
label | string | "Sidebar" | Accessible name. |
defaultWidth | number | 240 | Starting width in pixels. |
min | number | 180 | Narrowest width. |
max | number | 420 | Widest width. |
onResize | (width: number) => void | Called as the width changes. | |
className | string | Classes for the root element. |
It has no animation, so reduced motion changes nothing.