Playground

Resizable

Panels separated by handles you drag or move with the keyboard.

  • Built on native elements
  • 3 parts, named exports
  • Each handle is a focusable role="separator" with aria-orientation, aria-valuenow, aria-valuemin, aria-valuemax and aria-controls pointing at the panel it resizes.
  • Arrow keys resize by the step (horizontal groups use Left/Right, vertical groups Up/Down; mirrored in right-to-left); PageUp/PageDown resize by double; Home and End jump to the limits.
  • minSize and maxSize are enforced for both keyboard and pointer, and are reflected in aria-valuemin and aria-valuemax.
  • Styles in one file: resizable.css

Import

import '@monoline/css';
import {ResizablePanelGroup} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add resizable

Usage

import {ResizableHandle, ResizablePanel, ResizablePanelGroup} from '@monoline/react';

const box = {padding: 'var(--s4)', fontSize: 'var(--text-sm)'};

<ResizablePanelGroup style={{height: '200px', border: '1px solid var(--rule)'}}>
  <ResizablePanel defaultSize={30} minSize={15}><div style={box}>Sidebar</div></ResizablePanel>
  <ResizableHandle aria-label="Resize sidebar" />
  <ResizablePanel defaultSize={70}><div style={box}>Content</div></ResizablePanel>
</ResizablePanelGroup>

Anatomy

Import the parts you need and nest them like this.

import {ResizablePanelGroup, ResizablePanel, ResizableHandle} from '@monoline/react';

<ResizablePanelGroup>
  <ResizablePanel />
  <ResizableHandle />
</ResizablePanelGroup>

Examples

Horizontal

Focus a handle and use the arrow keys, Home and End.

Vertical, three panels

Props

ResizablePanelGroupProps

PropTypeDefaultDescription
direction"vertical" | "horizontal"'horizontal'`horizontal` puts panels side by side; `vertical` stacks them. Default `horizontal`.
stepnumber5Percent a panel grows or shrinks per arrow-key press (PageUp/PageDown use double). Default 5.
onLayoutChange((sizes: number[]) => void)–Called with every panel's size in percent (they add up to 100) after each resize.
children requiredReactNode–`ResizablePanel` and `ResizableHandle` elements, alternating, as direct children: panel, handle, panel...

ResizablePanelProps

PropTypeDefaultDescription
defaultSizenumber–Starting size in percent. Panels without one share what is left equally.
minSizenumber–Smallest size in percent. Default 10.
maxSizenumber–Largest size in percent. Default 100.

ResizableHandleProps

PropTypeDefaultDescription
aria-labelstring–Names the handle for screen readers. Default "Resize panels".

Data Attributes

State is exposed through attributes. Style it with these selectors, not with class toggles.

AttributeStylesheet
[data-direction="horizontal"]resizable.css
[data-direction="vertical"]resizable.css
[data-dragging]resizable.css

CSS classes

ClassStylesheet
.resizableresizable.css
.resizable-handleresizable.css
.resizable-panelresizable.css

Customization

Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.

app.css
.resizable {
  border-color: var(--accent);
}
.resizable[data-direction="horizontal"] {
  background: var(--wash);
}

Accessibility

  • Each handle is a focusable role="separator" with aria-orientation, aria-valuenow, aria-valuemin, aria-valuemax and aria-controls pointing at the panel it resizes.
  • Arrow keys resize by the step (horizontal groups use Left/Right, vertical groups Up/Down; mirrored in right-to-left); PageUp/PageDown resize by double; Home and End jump to the limits.
  • minSize and maxSize are enforced for both keyboard and pointer, and are reflected in aria-valuemin and aria-valuemax.
  • Handles are at least 24 CSS px to grab and show the focus ring.

Keyboard

KeysAction
Arrow keysResize by the step (horizontal groups use Left/Right, vertical groups Up/Down
PageUp / PageDownResize by double
Home / EndJump to the limits