Skip to content

Layout

Splitter

Resizable split panels with draggable, keyboard-operable dividers.

import { Splitter } from '@var-ui/react';

Splitter

Two or more panels separated by dividers the user can drag or move with the keyboard, side by side or stacked. It follows the APG window splitter pattern and is built on ResizeHandle for the divider, so pointer capture, arrow keys and Home/End behave exactly like the resizable sidebars in Layout.

Sizes are percentages of the combined panel space (the container minus the dividers), one per panel, summing to 100. They are never pixels, so the same defaultSizes work at any width and on the server. Resizing writes one CSS custom property per panel (flex: <size> 1 0%); panels clip or scroll their content (min-width: 0, overflow: auto) instead of forcing themselves open.

Give the Splitter a size along its main axis (a height for vertical, a width from its parent for horizontal); the panels share what it has.

Examples

Two panes

defaultSizes seeds the split (uncontrolled), minSizes / maxSizes clamp each panel. Double-click a divider to reset its two neighbours to defaultSizes.

Sidebar
Content. Drag the divider, or focus it and use the arrow keys.
Demo.tsxTSX
import { Splitter } from '@var-ui/react';

export default function Preview() {
  return (
    <Splitter defaultSizes={[30, 70]} minSizes={[15, 30]} style={{ height: '12.5rem' }}>
      <Splitter.Panel>
        <div style={{ padding: '0.75rem' }}>Sidebar</div>
      </Splitter.Panel>
      <Splitter.Panel>
        <div style={{ padding: '0.75rem' }}>Content. Drag the divider, or focus it and use the arrow keys.</div>
      </Splitter.Panel>
    </Splitter>
  );
}

Three panes

Each divider moves only the two panels next to it; the others keep their size.

Navigation
Editor
Inspector
Demo.tsxTSX
import { Splitter } from '@var-ui/react';

export default function Preview() {
  return (
    <Splitter defaultSizes={[20, 50, 30]} minSizes={[10, 20, 10]} style={{ height: '12.5rem' }}>
      <Splitter.Panel>
        <div style={{ padding: '0.75rem' }}>Navigation</div>
      </Splitter.Panel>
      <Splitter.Panel>
        <div style={{ padding: '0.75rem' }}>Editor</div>
      </Splitter.Panel>
      <Splitter.Panel>
        <div style={{ padding: '0.75rem' }}>Inspector</div>
      </Splitter.Panel>
    </Splitter>
  );
}

Vertical

orientation="vertical" stacks the panels and uses ArrowDown / ArrowUp.

Editor
Terminal
Demo.tsxTSX
import { Splitter } from '@var-ui/react';

export default function Preview() {
  return (
    <Splitter orientation="vertical" defaultSizes={[60, 40]} style={{ height: '16.25rem' }}>
      <Splitter.Panel>
        <div style={{ padding: '0.75rem' }}>Editor</div>
      </Splitter.Panel>
      <Splitter.Panel minSize={15}>
        <div style={{ padding: '0.75rem' }}>Terminal</div>
      </Splitter.Panel>
    </Splitter>
  );
}

Collapsible sidebar

Mark a panel collapsible (or pass collapsible to Splitter, as true or one flag per panel). Enter on the divider collapses the panel to zero and restores its previous size. Dragging a collapsible panel below half its minimum, or arrowing below it, collapses it too. This demo is controlled with sizes and onSizesChange.

Sidebar. Press Enter on the divider to collapse it.
Content
Sidebar: 25%
Demo.tsxTSX
import { Splitter } from '@var-ui/react';
import { useState } from 'react';

export default function Preview() {
  const [sizes, setSizes] = useState([25, 75]);

  return (
    <div style={{ display: 'grid', gap: '0.5rem' }}>
      <Splitter sizes={sizes} onSizesChange={setSizes} style={{ height: '12.5rem' }}>
        <Splitter.Panel collapsible minSize={15}>
          <div style={{ padding: '0.75rem' }}>Sidebar. Press Enter on the divider to collapse it.</div>
        </Splitter.Panel>
        <Splitter.Panel>
          <div style={{ padding: '0.75rem' }}>Content</div>
        </Splitter.Panel>
      </Splitter>
      <span>Sidebar: {sizes[0]}%</span>
    </div>
  );
}

Persisted

autoSaveId saves the sizes in localStorage (var-ui-splitter:<id>). The first render always uses defaultSizes so server and client markup match; the saved sizes are applied right after mount.

Resize me, then reload the page.
The sizes are saved in localStorage.
Demo.tsxTSX
import { Splitter } from '@var-ui/react';

export default function Preview() {
  return (
    <Splitter autoSaveId="docs-splitter-demo" defaultSizes={[40, 60]} style={{ height: '12.5rem' }}>
      <Splitter.Panel>
        <div style={{ padding: '0.75rem' }}>Resize me, then reload the page.</div>
      </Splitter.Panel>
      <Splitter.Panel>
        <div style={{ padding: '0.75rem' }}>The sizes are saved in localStorage.</div>
      </Splitter.Panel>
    </Splitter>
  );
}

Nested

Splitters nest: put a Splitter inside a panel (give it height: '100%').

Files
Editor
Console
Demo.tsxTSX
import { Splitter } from '@var-ui/react';

export default function Preview() {
  return (
    <Splitter defaultSizes={[30, 70]} style={{ height: '17.5rem' }}>
      <Splitter.Panel>
        <div style={{ padding: '0.75rem' }}>Files</div>
      </Splitter.Panel>
      <Splitter.Panel>
        <Splitter orientation="vertical" defaultSizes={[65, 35]} style={{ height: '100%' }}>
          <Splitter.Panel>
            <div style={{ padding: '0.75rem' }}>Editor</div>
          </Splitter.Panel>
          <Splitter.Panel>
            <div style={{ padding: '0.75rem' }}>Console</div>
          </Splitter.Panel>
        </Splitter>
      </Splitter.Panel>
    </Splitter>
  );
}

Customising a divider

Dividers are rendered between consecutive panels automatically. To label or style one, place a Splitter.Handle between the two panels; it renders nothing itself, and its props (className, style, aria-label, id, ref, handlers) are applied to that divider:

TSX
<Splitter>
  <Splitter.Panel>Files</Splitter.Panel>
  <Splitter.Handle aria-label="Resize file tree" />
  <Splitter.Panel>Editor</Splitter.Panel>
</Splitter>

Panels and handles must be direct children (not wrapped in a fragment or component). The default divider name is “Resize panels”; override it with handleLabel.

Props

onChange is the native change event of the root <div>: it only fires for form controls inside the panels, bubbling up. Use onSizesChange for sizes.

Accessibility

Each divider is role="separator" with tabindex="0", aria-orientation (a vertical separator for side-by-side panels, per the APG), aria-valuenow (the size of the panel before it, in percent), aria-valuemin / aria-valuemax (the limits implied by both neighbours), and aria-controls pointing at that panel’s id. Give panels an aria-label or heading when they are landmarks.

Pointer drags use pointer capture, so they keep tracking outside the divider, and the hit area extends well past the visible line for touch. In a right-to-left context the horizontal arrows and drag direction are mirrored. The divider is drawn with CanvasText in forced-colors mode and shows the standard focus ring.

Keyboard

KeyBehavior
Tab / Shift+TabMoves focus to the next / previous divider.
ArrowRight / ArrowLeftHorizontal: grows / shrinks the panel before the divider by step (mirrored in RTL).
ArrowDown / ArrowUpVertical: grows / shrinks the panel before the divider by step.
Shift + arrowSame, by largeStep.
Home / EndSmallest / largest size allowed by both neighbours (Home collapses a collapsible panel).
EnterCollapses or restores a collapsible neighbour.
Double-clickResets the two neighbours to their defaultSizes ratio.