Resizable
Panels that the user resizes by dragging the separators between them or with the keyboard.
Resizable ports react-resizable-panels 4.5.8. Its layout engine is copied from upstream, and the parts are Svelte rewrites of its React components.
Anatomy
Import the component and assemble its parts:
Panels and separators must be direct children of their group’s element.
Examples
Sizes
defaultSize, minSize, maxSize and collapsedSize take a number of pixels or a string with a unit: %, px, em, rem, vh or vw. A string without a unit is a percentage.
Collapsible panels and methods
A collapsible panel collapses when it is resized below its minSize, and Enter on the separator toggles it. bind:this on a panel gives collapse(), expand(), getSize(), isCollapsed() and resize(). bind:this on a group gives getLayout() and setLayout().
Saving the layout
useDefaultLayout reads a saved layout from localStorage, or any storage with getItem and setItem, and returns callbacks that save the layout when it settles. Call it while the component initializes. Give each panel an id, so the saved sizes match their panels.
Reading an element
Put an attachment on a part to reach its element. The group, the separator and the outer element of a panel take it.
Keyboard
A focused separator resizes the panel before it. The arrow keys along the group’s orientation move it by 5%. Home and End move it to its limits, and Enter collapses or expands a collapsible panel.
API reference
Group
Wraps a set of resizable panels, laid out horizontally or vertically. Renders a <div> element.
defaultLayout ResizableLayout | undefined —
- Name
- Description
The layout the group starts with, such as one
useDefaultLayoutrestored. Read once at mount.- Type
ResizableLayout | undefined
disableCursor boolean | undefined false
- Name
- Description
Whether to leave the cursor alone. By default, the group sets the cursor to show the resize direction while the pointer hovers or drags an edge.
- Type
boolean | undefined- Default
false
onLayoutChange function | undefined —
- Name
- Description
Called while the layout changes. A pointer drag calls it on every move, so prefer
onLayoutChangedfor most cases.- Type
((layout: ResizableLayout) => void) | undefined
onLayoutChanged function | undefined —
- Name
- Description
Called once the layout has changed. A pointer drag calls it when the pointer is released. Save layouts from this callback.
- Type
((layout: ResizableLayout) => void) | undefined
resizeTargetMinimumSize { coarse: number; fine: number; } { coarse: 20, fine: 10 }
- Description
The minimum size, in pixels, of the area that starts a resize around a separator or a panel edge, for coarse (touch) and fine (mouse) pointers.
- Type
{ coarse: number; fine: number; }- Default
{ coarse: 20, fine: 10 }
disabled boolean | undefined false
- Name
- Description
Whether the panels of the group cannot be resized.
- Type
boolean | undefined- Default
false
orientation ResizableOrientation | undefined 'horizontal'
- Name
- Description
The direction the panels are laid out and resized in.
- Type
ResizableOrientation | undefined- Default
'horizontal'
id string | number | undefined —
- Name
- Description
Identifies the group within the application. Falls back to a generated id. The element also takes it as
data-testid.- Type
string | number | undefined
children Snippet —
- Name
- Description
The panels and separators of the group.
- Type
Snippet
style string | null | undefined —
- Name
- Description
Inline styles for the group element.
display,flex-direction,flex-wrapandoverflowcannot be overridden.- Type
string | null | undefined
data-group
data-testid
id, for test queries.Panel
Wraps resizable content, with optional size constraints and collapsible behavior. Renders a <div> element.
collapsedSize number | string | undefined '0%'
- Name
- Description
The panel's size when collapsed.
- Type
number | string | undefined- Default
'0%'
collapsible boolean | undefined false
- Name
- Description
Whether the panel collapses when it is resized below its
minSize.- Type
boolean | undefined- Default
false
defaultSize number | string | undefined —
- Name
- Description
The size the panel starts with. Without it, the group shares out the free space.
- Type
number | string | undefined
maxSize number | string | undefined '100%'
- Name
- Description
The largest size of the panel.
- Type
number | string | undefined- Default
'100%'
minSize number | string | undefined '0%'
- Name
- Description
The smallest size of the panel.
- Type
number | string | undefined- Default
'0%'
onResize function | undefined —
- Name
- Description
Called when the panel's size changes, with the new size, the
idprop and the previous size, which isundefinedon mount.- Type
((panelSize: ResizablePanelSize, id: string | number | undefined, prevPanelSize: ResizablePanelSize | undefined) => void) | undefined
id string | number | undefined —
- Name
- Description
Identifies the panel within its group. Falls back to a generated id. Saved layouts use it to match a size to its panel. The element also takes it as
data-testid.- Type
string | number | undefined
class string | undefined —
- Name
- Description
CSS class for the inner element that holds the content, so the class does not interfere with the flex layout.
- Type
string | undefined
style string | null | undefined —
- Name
- Description
Inline styles for the inner element that holds the content.
- Type
string | null | undefined
data-panel
data-testid
id, for test queries.Separator
A focusable handle between two panels that resizes them with the pointer and the keyboard. Renders a <div> element.
id string | number | undefined —
- Name
- Description
Identifies the separator within its group. Falls back to a generated id. The element also takes it as
data-testid.- Type
string | number | undefined
style string | null | undefined —
- Name
- Description
Inline styles for the separator.
flex-growandflex-shrinkcannot be overridden.- Type
string | null | undefined
data-separator
hover), dragging it (active), or neither (inactive).data-testid
id, for test queries.