Two or more panels divided by separators you can drag or move with the arrow keys. Panels are plain flex children whose size is their flex-grow, so the layout and the initial sizes are CSS and correct before hydration. A small client script handles pointer events and the keyboard by rewriting the two neighbouring sizes directly, without React state. Separators follow the ARIA window splitter pattern.
Preview
Installation
Usage
import {
ResizableHandle,
ResizablePanel,
ResizablePanelGroup,
} from "@/components/ui/resizable"
export default function Example() {
return (
<ResizablePanelGroup
direction="horizontal"
className="h-40 max-w-md rounded-lg border"
>
<ResizablePanel defaultSize={50}>One</ResizablePanel>
<ResizableHandle withHandle />
<ResizablePanel defaultSize={50}>Two</ResizablePanel>
</ResizablePanelGroup>
)
}Examples
Vertical and nested
direction="vertical" stacks the panels. Groups nest freely: here a vertical group sits inside the second panel of a horizontal one. The group needs a height.
<ResizablePanelGroup direction="horizontal" className="h-52">
<ResizablePanel defaultSize={25}>One</ResizablePanel>
<ResizableHandle withHandle />
<ResizablePanel defaultSize={75}>
<ResizablePanelGroup direction="vertical">
<ResizablePanel defaultSize={30}>Two</ResizablePanel>
<ResizableHandle withHandle />
<ResizablePanel defaultSize={70}>Three</ResizablePanel>
</ResizablePanelGroup>
</ResizablePanel>
</ResizablePanelGroup>Limits
minSize and maxSize (percent of the group) stop a panel from shrinking or growing past a limit, for the mouse and for the keyboard. Here the sidebar stays between 20% and 40%.
<ResizablePanel defaultSize={30} minSize={20} maxSize={40}>
Sidebar
</ResizablePanel>Keyboard
Every separator is focusable and has role=separator with aria-valuenow, aria-valuemin and aria-valuemax (the size of the panel before it, in percent).
- ← →Resize 5% in a horizontal group (Shift: 10%)
- ↑ ↓Resize 5% in a vertical group (Shift: 10%)
- Home EndJump to the smallest and the largest size
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| direction | "horizontal" | "vertical" | "horizontal" | ResizablePanelGroup: horizontal puts panels side by side, vertical stacks them |
| defaultSize | number | - | ResizablePanel: initial size as a ratio, usually percent. Set it on all panels of a group or on none |
| minSize | number | - | ResizablePanel: smallest size, percent of the group |
| maxSize | number | - | ResizablePanel: largest size, percent of the group |
| withHandle | boolean | false | ResizableHandle: show a grip in the middle of the separator |
| aria-label | string | "Resize" | ResizableHandle: accessible name of the separator |
| className | string | - | Additional CSS classes on any part |
Features
- Layout and initial sizes are CSS (flex-grow), so the panes are right before hydration. Only dragging needs the script.
- Dragging rewrites the two neighbouring flex-grow values directly on the DOM: no React state and no re-render while you drag.
- Pointer events with pointer capture: mouse, touch and pen, and the drag does not stop when the pointer leaves the separator.
- role=separator, tabIndex 0, aria-orientation, aria-valuenow, aria-valuemin and aria-valuemax; arrow keys, Home and End.
- Works in right-to-left layouts: the horizontal direction is mirrored.
- The group needs a size along its direction (h-64, h-full or a fixed width). Separators must be direct children of the group, each between two panels.
- Sizes are not saved and there is no onLayout callback: the script only owns the DOM. Read the aria-valuenow of a separator if you need a size.