resizable

onChange called 0 time(s)

Files
Editor
Notes
import { resizable } from '@markless/ui';export default function Workspace() @{	<resizable.root class="group" defaultSizes={{ files: 28, editor: 44, notes: 28 }}>		<resizable.item class="pane" value="files">			<span class="pane-name">Files</span>		</resizable.item>		<resizable.thumb class="divider" value="files" min={15} max={55} aria-label="Resize files" />		<resizable.item class="pane" value="editor">			<span class="pane-name">Editor</span>		</resizable.item>		<resizable.thumb class="divider" value="editor" min={20} max={70} aria-label="Resize editor" />		<resizable.item class="pane" value="notes">			<span class="pane-name">Notes</span>		</resizable.item>	</resizable.root>;}

Drag a divider, or focus one and press an arrow key. Each panel prints its share as it changes.

resizable splits an area into panels, with dividers you drag to change their sizes. Use it for layouts such as a file list beside an editor.

Each panel has a name, its value. Each divider names the panel it resizes. Sizes are shares of the group from 0 to 100, kept in one record keyed by those names.

A divider moves one pair of panels: the panel it names and the panel after it. One grows by the same amount the other shrinks. So every other panel in the row stays put.

Anatomy

resizable anatomy
Anatomy perspectiveFlat
Layers
Sidebar⋮Your canvas
resizable.root

A row or column of panels a person can resize by dragging or arrowing the dividers between them.

  • resizable.root is the group. It holds the sizes record.
  • resizable.item is one panel. Its value names it.
  • resizable.thumb is a divider. Its value names the panel it resizes.

Each panel writes its share as a --size custom property. The family lays out the group with that property, under @layer markless. The parts write ui-panels, ui-panel, ui-divider, ui-orientation, ui-value, ui-size, ui-min, ui-max, ui-collapsible, ui-collapsed, ui-dragging and ui-disabled.

Stack them instead

Set orientation="vertical" and the panels stack, with the dividers across them. The arrows follow the group. Up and down move a divider in a vertical group. Left and right move it in a horizontal one.

<resizable.root orientation="vertical" defaultSizes={{ top: 60, bottom: 40 }}>

A panel can hold a group of its own. Give that resizable.item an orientation, and put more panels and dividers inside it. A divider in the inner group moves only its own pair.

A panel that folds away

Give a divider collapsible. Enter then folds its panel down to collapsedSize. The next Enter puts back the size the panel had before it folded.

<resizable.thumb value="files" min={15} max={55} collapsible collapsedSize={5} aria-label="Resize files" />

Hold the sizes yourself

Pass sizes to control the widget. A drag or a key reports the new record through onChange. Nothing moves until your new record comes back in. onChangeEnd fires once the change settles: when the pointer lifts, or after a key press. Pass defaultSizes instead to let the widget keep its own record.

<resizable.root sizes={held} onChange={setHeld} onChangeEnd={save}>

Keyboard

Focus sits on a divider. Every key moves the panel that divider names. In right-to-left text the two horizontal arrows swap.

Key What it does
Left arrow or Right arrow Moves the divider one step, in a side-by-side group.
Up arrow or Down arrow Moves the divider one step, in a stacked group.
Shift and an arrow Moves it ten steps at once.
Home Shrinks the panel to the divider's min.
End Grows the panel to the divider's max.
Enter Folds the panel away, then puts it back. Needs collapsible.
Escape Stops a drag and puts back the sizes it started from.

API

Every prop is optional unless its row says it is required. ResizableSizes is Record<string, number>. ResizableOrientation is 'horizontal' | 'vertical'.

resizable.root

Prop Type What it does
sizes ResizableSizes The sizes in force. It makes the widget controlled. Nothing moves until a new record comes in.
defaultSizes ResizableSizes The starting sizes of an uncontrolled widget. A panel you leave out gets an equal share.
orientation ResizableOrientation The axis the panels sit along. Omit it and they sit side by side.
step number How far one arrow key moves a divider, in points of the group. The default is 1.
disabled boolean Stops all resizing.
onChange (sizes: ResizableSizes) => void Gets every panel's size each time one changes, also during a drag.
onChangeEnd (sizes: ResizableSizes) => void Gets the sizes once a change settles.

Shift multiplies step by ten.

Attribute Present when Use it for
ui-panels Always Marks the element as a group of panels.
ui-orientation Always horizontal or vertical, the axis the panels sit along.
ui-disabled You set disabled. The look of a group that does not respond.
ui-dragging A divider in this group is in a drag. The look of a busy group.
Selector Default Why
[ui-panels] display: flex; flex-direction: row The group lays out the panels along its axis.
[ui-panels][ui-orientation="vertical"] flex-direction: column The same group, stacked.

The root passes anything a <div> accepts to its element, except onChange.

resizable.item

Prop Type What it does
value string Required. The panel's name. It keys the sizes record and becomes the panel's id.
orientation ResizableOrientation Makes this panel hold a nested group, laid out along that axis.

The value becomes an id, so it must be unique on the page.

Attribute Present when Use it for
id Always The panel's value. A divider's aria-controls points here.
style The panel has a size. Carries --size, the panel's share. The family owns this attribute.
ui-panel Always Marks the element as a panel.
ui-value Always The panel's name, so one selector can reach one panel.
ui-orientation The panel holds a nested group. The axis of that nested group.
ui-size The panel has a size. The share, rounded to two decimals.
ui-collapsed The panel is folded away. The folded look.

If you write your own id, write the matching aria-controls on the divider too.

Selector Default Why
[ui-panel] flex: var(--size, 1) 1 0; overflow: hidden; min-inline-size: 0; min-block-size: 0 The share is the grow factor. A panel with no size gets an equal share.
[ui-panel][ui-orientation="horizontal"] display: flex; flex-direction: row A panel that holds a nested group lays it out.
[ui-panel][ui-orientation="vertical"] display: flex; flex-direction: column The same, stacked.

The panel passes anything a <div> accepts to its element, except style.

resizable.thumb

Name each divider with aria-label. VoiceOver ignores a divider's own aria-label and title, so the divider moves your text into a visually hidden element inside it and points aria-labelledby at it. Every screen reader then reads the same name. Name the divider with aria-label, not with your own aria-labelledby. The family writes aria-labelledby itself, so yours would be replaced.

Prop Type What it does
value string Required. The name of the panel this divider resizes and reports.
min number The smallest share that panel can have. The default is 0.
max number The largest share that panel can have. The default is 100.
collapsible boolean Lets Enter fold the panel and bring it back.
collapsedSize number The panel's share while it is folded. The default is 0.
orientation ResizableOrientation The axis of the group this divider sits in. Omit it to use the root's axis.
aria-label string The divider's name. It is read through aria-labelledby, as described above.
Attribute Present when Use it for
role Always separator. A screen reader announces it as a window splitter.
tabindex Always 0, or -1 while the group is disabled.
aria-controls Always The id of the panel this divider resizes.
aria-orientation Always The divider's own axis. A side-by-side group has upright dividers.
aria-valuemin, aria-valuemax Always The divider's min and max.
aria-valuenow The panel has a size. The panel's share.
aria-valuetext The panel has a size. The share as a percentage, such as 28%.
aria-disabled Always true or false.
aria-labelledby Always The id of a hidden element holding your aria-label.
ui-divider Always Marks the element as a divider.
ui-value Always The name of the panel this divider resizes.
ui-orientation Always The axis of the group this divider sits in.
ui-min, ui-max Always The limits, for your stylesheet.
ui-collapsible You set collapsible. Shows that Enter folds this one.
ui-collapsed The panel is folded away. The folded look.
ui-dragging This divider is in a drag. The gripped look.
ui-disabled The group is disabled. The look of a divider that does not respond.
Selector Default Why
[ui-divider] flex: none; touch-action: none A divider takes no share. A drag along it does not scroll the page.
[ui-divider][ui-orientation="horizontal"] cursor: col-resize The pointer shows which way it moves.
[ui-divider][ui-orientation="vertical"] cursor: row-resize The same, stacked.
[ui-divider][ui-disabled] cursor: default Nothing to grip.

A divider has no name of its own. Write an aria-label on each one that names the panel it resizes. A group with several dividers needs each one told apart. The divider passes anything a <div> accepts to its element.