Skip to Content
zjkm-ui
Components

Resizable Sidebar

A sidebar you can drag wider or narrower.

Drag the edge, or focus it and use the arrow keys.
Props
<ResizableSidebar label="Files">
  <FileTree />
</ResizableSidebar>

Installation

npx shadcn@latest add https://ui.zjkm.tech/r/resizable-sidebar.json
import { 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

PropTypeDefaultDescription
childrenReactNodeThe sidebar's content.
labelstring"Sidebar"Accessible name.
defaultWidthnumber240Starting width in pixels.
minnumber180Narrowest width.
maxnumber420Widest width.
onResize(width: number) => voidCalled as the width changes.
classNamestringClasses for the root element.

It has no animation, so reduced motion changes nothing.

On this page