Examples

Sidebar and content

Enter collapses the first pane and restores it.

Preview
Quarterly review

Focus the divider and press ← or →, Home or End; Enter collapses the mailboxes.

Example.tsx
import { Splitter } from '@reactloom/ui';

export default function Example() {
  return (
    <div style={{ blockSize: 260, inlineSize: '100%', border: '1px solid var(--pl-color-border-default)', borderRadius: 8, overflow: 'hidden' }}>
      <Splitter aria-label="Mailboxes" defaultSize={28} minSize={15} maxSize={60}>
        <nav aria-label="Mailboxes" style={{ padding: 12 }}>
          <strong>Mailboxes</strong>
          <ul style={{ margin: '8px 0 0', paddingInlineStart: 18 }}>
            <li>Inbox</li>
            <li>Sent</li>
            <li>Archive</li>
          </ul>
        </nav>
        <section aria-label="Message" style={{ padding: 12 }}>
          <strong>Quarterly review</strong>
          <p style={{ margin: '8px 0 0' }}>Focus the divider and press ← or →, Home or End; Enter collapses the mailboxes.</p>
        </section>
      </Splitter>
    </div>
  );
}

Nested and controlled

A vertical splitter inside a horizontal one; size is controlled.

Preview
Files
Editor (65%)
Terminal
Example.tsx
import { Splitter } from '@reactloom/ui';
import { useState } from 'react';

export default function Example() {
  const [editor, setEditor] = useState(65);
  return (
    <div style={{ blockSize: 300, inlineSize: '100%', border: '1px solid var(--pl-color-border-default)', borderRadius: 8, overflow: 'hidden' }}>
      <Splitter aria-label="Files" defaultSize={25}>
        <div style={{ padding: 12 }}>Files</div>
        <Splitter aria-label="Editor" orientation="vertical" size={editor} onSizeChange={setEditor} minSize={30}>
          <div style={{ padding: 12 }}>Editor ({Math.round(editor)}%)</div>
          <div style={{ padding: 12, background: 'var(--pl-color-bg-subtle)', blockSize: '100%' }}>Terminal</div>
        </Splitter>
      </Splitter>
    </div>
  );
}

API reference

Splitter props
PropTypeDefault
childrenrequired
The two panes.
[ReactNode, ReactNode]—
aria-labelrequired
Name of the separator — usually the first pane’s name.
string—
orientation
Horizontal puts the panes side by side.
'horizontal' | 'vertical''horizontal'
size / defaultSize / onSizeChange
First pane in percent.
number50
minSize · maxSize
Limits in percent.
number10 · 90
step
Arrow-key step.
number5
collapsible
Enter collapses and restores.
booleantrue

Customization

Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[data-dragging]present when on
[data-orientation]horizontal · vertical

Theme tokens it reads

--pl-color-accent-solid --pl-color-border-default --pl-color-border-strong --pl-focus-ring-color --pl-focus-ring-width --pl-radius-full --pl-radius-xs

Accessibility

  • The divider is role="separator" with aria-valuenow, aria-controls (the first pane) and a name.
  • Arrow keys follow the reading direction in right-to-left layouts.
  • Pointer drags use pointer capture, so the pointer can leave the handle.
Keyboard interactions
KeyAction
← → (or ↑ ↓)Resize by a step
Home / EndMinimum / maximum
EnterCollapse or restore the first pane

Usage guidelines

Do

  • Give each pane a landmark or heading so people know what they resize.
  • Remember the size between visits.

Don’t

  • Don’t put essential content in a pane that can collapse without a way back.