Resizable
Panels separated by handles you drag or move with the keyboard.
SourceStyles source@monoline/react 0.5.0Markdown for AI toolsstable
- 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
Vertical, three panels
Props
ResizablePanelGroupProps
| Prop | Type | Default | Description |
|---|---|---|---|
direction | "vertical" | "horizontal" | 'horizontal' | `horizontal` puts panels side by side; `vertical` stacks them. Default `horizontal`. |
step | number | 5 | Percent 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 required | ReactNode | – | `ResizablePanel` and `ResizableHandle` elements, alternating, as direct children: panel, handle, panel... |
ResizablePanelProps
| Prop | Type | Default | Description |
|---|---|---|---|
defaultSize | number | – | Starting size in percent. Panels without one share what is left equally. |
minSize | number | – | Smallest size in percent. Default 10. |
maxSize | number | – | Largest size in percent. Default 100. |
ResizableHandleProps
| Prop | Type | Default | Description |
|---|---|---|---|
aria-label | string | – | 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.
| Attribute | Stylesheet |
|---|---|
[data-direction="horizontal"] | resizable.css |
[data-direction="vertical"] | resizable.css |
[data-dragging] | resizable.css |
CSS classes
| Class | Stylesheet |
|---|---|
.resizable | resizable.css |
.resizable-handle | resizable.css |
.resizable-panel | resizable.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
| Keys | Action |
|---|---|
| Arrow keys | Resize by the step (horizontal groups use Left/Right, vertical groups Up/Down |
| PageUp / PageDown | Resize by double |
| Home / End | Jump to the limits |