Splitter
Two panes with a handle you can drag or move with the arrow keys.
Demo
Usage
import { Splitter } from '@tuttn/slant'
// Uncontrolled: the first pane starts at defaultValue percent (50 when omitted).
<Splitter defaultValue={30} style={{ height: 320 }}>
<Splitter.Pane><FolderTree /></Splitter.Pane>
<Splitter.Pane><FileTable /></Splitter.Pane>
</Splitter>
// Controlled and stacked, with bounds, a bigger step and a spoken value.
<Splitter orientation="vertical" value={split} onValueChange={setSplit}
min={20} max={80} step={10} label="Resize editor and console"
format={value => `Editor ${Math.round(value)}%`} style={{ height: 480 }}>
<Splitter.Pane><Editor /></Splitter.Pane>
<Splitter.Pane><Console /></Splitter.Pane>
</Splitter>Props
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | 'horizontal' | 'vertical' | 'horizontal' | How the panes are laid out: side by side (`horizontal`, a vertical handle moved with Left and Right) or stacked (`vertical`, a horizontal handle moved with Up and Down). Stacked panes need a root with a height. |
value | number | — | The first pane's share of the root, 0–100, when controlled. Clamped to `min`…`max`. |
defaultValue | number | 50 | The first pane's share when uncontrolled. A double click on the handle returns to it. |
onValueChange | (value: number) => void | — | Called with the first pane's new share (a percentage) as the handle moves. |
min | number | 10 | The smallest share the first pane can have. Home and Enter's collapse go here. |
max | number | 90 | The largest share the first pane can have. End goes here. |
step | number | 5 | How far one arrow key moves the handle, in percent. |
label | string | messages.resizePanes ("Resize panes") | The handle's accessible name. |
format | (value: number) => string | — | Turns the value into the text screen readers read (`aria-valuetext`), e.g. `v => \`${v}% for the folders\``. |
children | ReactNode | — | Exactly two `Splitter.Pane`s. The handle goes between them. |
Splitter.Pane …rest | HTMLAttributes | — | className, style, other attributes and the ref go on the pane's div. The first pane's id (generated when you leave it out) is the one the handle's aria-controls names. |
…rest | HTMLAttributes | — | className, style, other attributes and the ref go on the root div. The root sets --sl-split, the first pane's share, in its style. |
The handle is the APG window splitter: a focusable role="separator" whose value (aria-valuenow, between min and max) is the first pane's share in percent, and whose aria-controls names the first pane. Side by side, Left and Right move it by step; under right-to-left text the first pane sits on the right, so Right shrinks it. Stacked, Up and Down move it. Home goes to min, End to max, and Enter collapses the first pane to min and, pressed again, restores where it was.
A drag with a mouse, pen or finger captures the pointer and sets the share from where it sits in the root, clamped to min and max; a double click goes back to defaultValue.
Pass exactly two Splitter.Panes. Each can shrink to nothing and scrolls its own overflow; stacked panes need a root with a height. A pane that scrolls but holds nothing focusable should be reachable from the keyboard: give it tabIndex={0}, role="region" and an aria-label, or put a ScrollArea in it.