shadcn.io is an independent project built on shadcn/ui
Components
Free
Resizable for Svelte UI SDK
Panels that trade space when people drag the handle between them or press an arrow key, for a file tree beside an editor. For Svelte and UI SDK apps.
On this page9 sections
Resizable splits an area into panels with a handle between them, and dragging the handle gives one panel the space it takes from the other. Reach for it when people should choose the split themselves: a file tree beside an editor, a list of messages beside the open one, a query over its results.
For an app's main navigation that folds away, use a Sidebar. This Resizable wraps the Resizable from UI SDK, with each panel's limits listed by its id in panels on the group.
Installation
Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.
Each handle is a focusable element with the separator role and the label Resize. It reports the size of the panel before it, as a percentage of the group, in aria-valuenow, with that panel's limits in aria-valuemin and aria-valuemax. Every handle gets the same label, so where a layout has more than one, pass aria-label to each ResizableResizeTrigger to name what it resizes, such as Resize file tree. A panel that collapses to nothing turns inert, so Tab skips its links, but one with a collapsedSize above 0 keeps them in reach.
KeyAction
Tab
Moves focus to the next handle or focusable element, in page order.
Arrow Left
In a horizontal group, moves the handle left by 5% of the group's width, or by 10% with Shift held.
Arrow Right
In a horizontal group, moves the handle right by 5% of the group's width, or by 10% with Shift held.
Arrow Up
In a vertical group, moves the handle up by 5% of the group's height, or by 10% with Shift held.
Arrow Down
In a vertical group, moves the handle down by 5% of the group's height, or by 10% with Shift held.
Home
Shrinks the panel before the handle to its minimum, or collapses it when it is collapsible.
End
Grows the panel before the handle to the largest size its limits allow.
Enter
Collapses the panel before the handle, or expands it again, when that panel is collapsible. When only the panel after it is, Enter works on that one.
Demos
Vertical
A header pane over a content pane, split a quarter to three quarters, with orientation set to vertical and a plain line for the handle. The group has min-h-[200px], because a vertical split divides whatever height its container gives it. Use this for a toolbar over a canvas, or a query editor over its results.
Handle
A sidebar pane and a content pane, a quarter and three quarters wide, with withHandle drawing a small grip on the line between them. The grip tells people the edge moves, which a 1px line on a light page doesn't. Leave it off where the panels' own borders already read as a split, as in the Vertical demo.
Collapsible
A file tree beside an editor, with collapsible and a minSize of 25 in the tree's entry in panels. The Hide files button in the editor's toolbar calls collapsePanel or expandPanel from useResizable, and dragging the handle past half the minimum snaps the tree shut. While it is collapsed the panel is inert, so Tab skips its files.
RTL
The nested layout from the top of the page with Arabic labels, inside a Direction provider set to rtl, which puts panel one on the right. UI SDK reads the direction the provider writes on the page, so the outer handle follows the pointer and each arrow key moves it the way the arrow points. Home sends the handle to the right end and End to the left.
FAQ
How do I set the starting size of each Resizable panel?
List the sizes in defaultSize on Resizable, one number per panel in the order of panels, each a percentage of the group: [30, 70] gives the first panel 30% of the width. A panel you leave without a size shares what remains with the others.
The Handle demo starts its sidebar at a quarter of the width this way.
How do I give a Resizable panel a minimum width?
Add minSize to that panel's entry in panels, and maxSize for a ceiling. Both are percentages of the group, so minSize: 20 stops the panel at a fifth of the width. Dragging and the arrow keys both stop at the limit.
A floor matters most for a file tree or a list whose names turn unreadable when squeezed. Make that panel collapsible as well if people should be able to close it entirely.
How do I stack a Resizable vertically?
Set orientation to vertical on Resizable, and the panels stack with the handle running across the width. A vertical group divides the height of its container, so give it a height or a minimum height, as the Vertical demo does with min-h-[200px].
Groups nest, too. Put a vertical Resizable inside one panel of a horizontal one, as the demo at the top of the page does, and the inner sizes become shares of that panel rather than of the page.
How do I save Resizable panel sizes between visits?
Pass onResizeEnd to Resizable, whose first argument is an array of percentages in panel order, and write it to localStorage. On the next load, read it back and pass it as defaultSize, with your usual sizes as the fallback when nothing is stored. The callback runs once a drag is released, a key comes up or a panel collapses, not on every pointer move.
How do I collapse a Resizable panel from a button?
Set collapsible to true and give a minSize in that panel's entry in panels. Dragging it more than halfway from minSize toward collapsedSize, which is 0 unless you set it, snaps it shut. For a button rendered inside Resizable, useResizable gives access to the group's collapsePanel and expandPanel, which take the panel's id.
Pressing Enter on the handle does the same for the panel before it. A panel collapsed to nothing turns inert by itself, so Tab skips its content. With a collapsedSize above 0, set inert on the panel while it is closed, as the Collapsible demo does.
Can I use a Resizable from the keyboard in Svelte?
Yes, every handle is a stop in the tab order, and once it has focus the arrow keys along the split move it 5% of the group per press, or 10% with Shift. Home and End push it to either limit, and Enter collapses or expands a collapsible panel. Set keyboardResizeBy on Resizable to change the 5% step, and largeStep for the one with Shift.
How do I make the Resizable handle easier to see and grab?
Set withHandle to true on ResizableResizeTrigger to draw a small grip on the line, as the Handle demo does. The line itself is 1px wide, and the trigger's after pseudo-element lays a 4px strip over it.
UI SDK widens the target beyond that, centering a strip 10px wide on the line for a mouse and 24px for touch. The handle sets data-hovering while the pointer is over that strip and data-dragging while it is dragged, so a class keyed on either can color the line.
Should I use Resizable or a Sidebar for an app's side panel?
Use a Sidebar for the app's main navigation. It folds to a rail of icons or slides off screen, and a button or Ctrl+B toggles it, which is what people expect of the column that holds an app's links.
Use Resizable when the width itself is the reader's choice, for content panes such as a file tree, a list beside its detail, or a preview beside the code. The two combine well: a Sidebar for navigation and a Resizable inside the page for its panes.
API Reference
Resizable
<div>data-slot="resizable"
PropType
layout?number[]
Each panel's size in percent, in panel order, like [25, 75]. Pass it to control the group. Two-way with bind:layout.
defaultLayout?Layout
Each panel's starting size in percent, by panel id.
onLayoutChange?(layout: Layout) → void
Runs on every change of the layout, every frame of a drag included.
Parameters
layout – Layout
Returns
void
autoSaveId?string
Saves the layout when an interaction completes and restores it on the next visit, under this key. Give panels an id so it survives changes elsewhere on the page.
controller?ResizableController
Resizes the group from anywhere. Create one with createResizableController().
debug?boolean
Logs every state change with its reason to the console, in development builds.
disabled?boolean
Stops every handle: no drags, no keys, and handles leave the tab order.
elementRef?React.Ref<HTMLDivElement | null>
The group's root element.
Type
React.Ref<HTMLDivElement | null>
groupRef?React.Ref<GroupImperativeHandle | null>
Reads and sets the layout by panel id.
Type
React.Ref<GroupImperativeHandle | null>
id?string | number
The element's id.
Type
string | number
largeStep?number
How far Shift with an arrow key moves a handle, in percent.
The direction panels are laid out in. Horizontal panels sit side by side, vertical ones stack.
Type
"horizontal" | "vertical"
Default
"horizontal"
step?number
How far an arrow key moves a handle, in percent. UI SDK's default: 1.
Default
5
storage?ResizableStorage
Where autoSaveId saves: anything with getItem and setItem, like a cookie store a server can read.
Default
localStorage
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
AttributeType
data-disabled?string
Present when the group, or this handle, is disabled.
data-dragging?string
Present while a handle of the group is being dragged.
data-orientation"horizontal" | "vertical"
The group's direction, on every part. A handle's own aria-orientation is the other one, since it runs across the group.
Type
"horizontal" | "vertical"
ResizablePanel
<div>data-slot="resizable-panel"
PropType
collapsedSize?number | string
The size it collapses to. Numbers are pixels; strings take %, px or rem, and no unit is percent.
Type
number | string
collapsible?boolean
Lets the panel collapse below its minimum to collapsedSize: by dragging past half the way there, with Enter or a double-click on its handle, or through the controller.
defaultSize?number | string
Where it starts. Numbers are pixels; strings take %, px or rem, and no unit is percent.
Type
number | string
elementRef?React.Ref<HTMLDivElement | null>
The panel's element.
Type
React.Ref<HTMLDivElement | null>
id?string | number
The element's id.
Type
string | number
maxSize?number | string
The largest it gets. Numbers are pixels; strings take %, px or rem, and no unit is percent.
Type
number | string
minSize?number | string
The smallest it gets while open. Numbers are pixels; strings take %, px or rem, and no unit is percent.
panelSize – { asPercentage: number; inPixels: number }
id – string | number
prevPanelSize – { asPercentage: number; inPixels: number }
Returns
void
panelRef?React.Ref<PanelImperativeHandle | null>
Collapses, expands, reads and resizes the panel.
Type
React.Ref<PanelImperativeHandle | null>
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
AttributeType
data-collapsed?string
Present while a collapsible panel is collapsed.
data-orientation"horizontal" | "vertical"
The group's direction, on every part. A handle's own aria-orientation is the other one, since it runs across the group.
Type
"horizontal" | "vertical"
CSS variableType
--resizable-panel-growstring
--resizable-panel-sizestring
The panel's share of the group, as a percentage. Written on every frame of a drag, without a render.
ResizableResizeTrigger
<div>data-slot="resizable-handle"
PropType
disabled?boolean
Stops this handle: no drags and no keys, and it leaves the tab order.
withHandle?boolean
Whether to show the handle.
Default
false
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
AttributeType
data-disabled?string
Present when the group, or this handle, is disabled.
data-dragging?string
Present while this handle is being dragged.
data-hovering?string
Present while the pointer is over the handle or within its hit area, which reaches past the handle itself.
data-orientation"horizontal" | "vertical"
The group's direction, on every part. A handle's own aria-orientation is the other one, since it runs across the group.
Type
"horizontal" | "vertical"
ResizablePanelGroup
<div>data-slot="resizable"
PropType
layout?number[]
Each panel's size in percent, in panel order, like [25, 75]. Pass it to control the group. Two-way with bind:layout.
defaultLayout?Layout
Each panel's starting size in percent, by panel id.
onLayoutChange?(layout: Layout) → void
Runs on every change of the layout, every frame of a drag included.
Parameters
layout – Layout
Returns
void
autoSaveId?string
Saves the layout when an interaction completes and restores it on the next visit, under this key. Give panels an id so it survives changes elsewhere on the page.
controller?ResizableController
Resizes the group from anywhere. Create one with createResizableController().
debug?boolean
Logs every state change with its reason to the console, in development builds.
disabled?boolean
Stops every handle: no drags, no keys, and handles leave the tab order.
elementRef?React.Ref<HTMLDivElement | null>
The group's root element.
Type
React.Ref<HTMLDivElement | null>
groupRef?React.Ref<GroupImperativeHandle | null>
Reads and sets the layout by panel id.
Type
React.Ref<GroupImperativeHandle | null>
id?string | number
The element's id.
Type
string | number
largeStep?number
How far Shift with an arrow key moves a handle, in percent.