Resizable
@codeui/solid v0.3.0
Panels in a row or a column, split by handles the user drags to resize them.
When to use
Use Resizable when the user decides how much room two areas get: a sidebar next to a conversation, an editor over a console. The user drags a handle, or focuses it and uses the arrow keys.
When to choose another component
- Stack lays out fixed areas. Use it when the sizes are yours to choose, not the user's.
- Sheet is the side panel on a phone. Resizing needs a fine pointer or a keyboard, so swap to a sheet at 768px and below.
Live demo
import { Resizable, ResizableHandle, ResizablePanel, Text } from "@codeui/solid";
/** Padding goes on a child: on the panel it would add to the size Kobalte sets. */
const pane = { padding: "var(--cui-space-4)" };
export default function ResizableBasic() {
return (
<Resizable
style={{
height: "200px",
background: "var(--cui-surface-canvas)",
"border-radius": "var(--cui-radius-card)",
}}
>
<ResizablePanel initialSize={0.6} minSize={0.3}>
<Text as="div" weight="semibold" style={pane}>Editor</Text>
</ResizablePanel>
<ResizableHandle aria-label="Resize editor and preview" />
<ResizablePanel minSize={0.2}>
<Text as="div" weight="semibold" style={pane}>Preview</Text>
</ResizablePanel>
</Resizable>
);
}Put ResizablePanels in Resizable, with a ResizableHandle between each pair. Give the root a size: a height for a row, and both a width and a height for a column.
Anatomy
Tap a part to outline it in the demo.
- 01Resizable
resizableclasses.root - 02ResizablePanel
resizable-panelclasses.panel - 03ResizableHandle
resizable-handleclasses.handle
| Export | Renders | classes key | data-cui | Role |
|---|---|---|---|---|
Resizable | div with display: flex | root | resizable | none |
ResizablePanel | div with flex-basis set to its size | panel | resizable-panel | none |
ResizableHandle | button | handle | resizable-handle | separator |
Only the handle has kit styles. Style the panels yourself. Put padding on a child of the panel: on the panel it adds to the size Kobalte sets.
Variants
Vertical
import { Resizable, ResizableHandle, ResizablePanel, Text } from "@codeui/solid";
/** Padding goes on a child: on the panel it would add to the size Kobalte sets. */
const pane = { padding: "var(--cui-space-4)" };
export default function ResizableVertical() {
return (
<Resizable
orientation="vertical"
style={{
height: "280px",
background: "var(--cui-surface-canvas)",
"border-radius": "var(--cui-radius-card)",
}}
>
<ResizablePanel initialSize={0.7} minSize={0.3}>
<Text as="div" weight="semibold" style={pane}>fetch-retry.ts</Text>
</ResizablePanel>
<ResizableHandle aria-label="Resize editor and console" />
<ResizablePanel minSize={0.15}>
<Text as="div" weight="semibold" style={pane}>Console</Text>
</ResizablePanel>
</Resizable>
);
}orientation="vertical" stacks the panels. The handle draws a horizontal line and the arrow keys become Up and Down.
Sidebar with a minimum and a maximum width
import { Resizable, ResizableHandle, ResizablePanel, Text } from "@codeui/solid";
/** Padding goes on a child: on the panel it would add to the size Kobalte sets. */
const pane = { padding: "var(--cui-space-4)" };
export default function ResizableSidebar() {
return (
<Resizable
style={{
height: "240px",
background: "var(--cui-surface-canvas)",
"border-radius": "var(--cui-radius-card)",
}}
>
<ResizablePanel initialSize="240px" minSize="200px" maxSize="360px">
<Text as="div" weight="semibold" style={pane}>Snippets</Text>
</ResizablePanel>
<ResizableHandle aria-label="Resize snippet list" />
<ResizablePanel>
<Text as="div" weight="semibold" style={pane}>fetch-retry.ts</Text>
</ResizablePanel>
</Resizable>
);
}Sizes take a fraction of the root (0.25) or a pixel string ("240px"). Here the sidebar starts at 240px and stays between 200px and 360px. The panel without initialSize takes the space the others leave.
Islands
import { Resizable, ResizableHandle, ResizablePanel, Text } from "@codeui/solid";
/** Each island leaves 4px on the handle side, so two islands sit 8px apart and the handle fills the gap. */
const island = (side: "start" | "end") => ({
height: "100%",
"box-sizing": "border-box" as const,
padding: "var(--cui-space-4)",
[`margin-inline-${side}`]: "4px",
background: "var(--cui-surface-canvas)",
"border-radius": "var(--cui-radius-command)",
});
export default function ResizableIslands() {
return (
<Resizable style={{ height: "240px" }}>
<ResizablePanel>
<Text as="div" weight="semibold" style={island("end")}>
fetch-retry.ts
</Text>
</ResizablePanel>
<ResizableHandle
aria-label="Resize side panel"
style={{ "--cui-resizable-handle-line-color": "transparent" }}
/>
<ResizablePanel initialSize="360px" minSize="280px" maxSize="480px">
<Text as="div" weight="semibold" style={island("start")}>
Side panel
</Text>
</ResizablePanel>
</Resizable>
);
}The handle draws a 1px line in --cui-border-divider. In an Inkstone layout of islands, the 8px gap already separates them, and Inkstone allows no line between islands. Set --cui-resizable-handle-line-color: transparent on the handle there. The line still shows on hover, while dragging, and on keyboard focus.
States
Collapsible
import { createSignal } from "solid-js";
import { Resizable, ResizableHandle, ResizablePanel, Text } from "@codeui/solid";
/** Padding goes on a child: on the panel it would add to the size Kobalte sets. */
const pane = { padding: "var(--cui-space-4)" };
export default function ResizableCollapsible() {
const [collapsed, setCollapsed] = createSignal(false);
return (
<div style={{ display: "grid", gap: "var(--cui-space-2)" }}>
<Resizable
style={{
height: "240px",
background: "var(--cui-surface-canvas)",
"border-radius": "var(--cui-radius-card)",
}}
>
<ResizablePanel>
<Text as="div" weight="semibold" style={pane}>
fetch-retry.ts
</Text>
</ResizablePanel>
<ResizableHandle aria-label="Resize settings panel" />
<ResizablePanel
initialSize={0.35}
minSize={0.25}
collapsible
onCollapse={() => setCollapsed(true)}
onExpand={() => setCollapsed(false)}
>
<Text as="div" weight="semibold" style={pane}>
Settings
</Text>
</ResizablePanel>
</Resizable>
<Text tone="muted">{collapsed() ? "Settings is collapsed." : "Settings is open."}</Text>
</div>
);
}collapsible lets a panel collapse to collapsedSize (0 by default) when the user drags past its minSize, or presses Enter on the handle. onCollapse and onExpand report the change.
Controlled
Without sizes, the root manages the sizes. To control them, pass sizes as fractions that add up to 1, with onSizesChange. Save them to restore the layout on the next visit.
Ready API
Import from @codeui/solid/resizable or from @codeui/solid. Everything not listed here passes through to Kobalte's resizable.
Resizable
Prop
Type
ResizablePanel
Prop
Type
ResizableHandle
Give every handle an aria-label that names what it resizes.
Prop
Type
resizableStyles
resizableStyles.handle() returns the handle class, cui-resizable-handle. root() and panel() return an empty string. resizableParts maps each part to its data-cui value. ResizableSize is a fraction or a `${number}px` string. ResizeStrategy ("preceding", "following", "both") picks which neighbours give up space when a panel resizes from code.
Accessibility
Keyboard
| Key | Action |
|---|---|
| Tab | Focuses the handle. |
| ← → | Move a horizontal handle by keyboardDelta (0.1 of the root by default). |
| ↑ ↓ | Move a vertical handle by keyboardDelta. |
| Shift + arrow | Moves the handle as far as the panels allow. |
| Home End | Move the handle to the minimum or the maximum size. |
| Enter | Collapses or expands the nearest collapsible panel. |
ARIA
- The handle has
role="separator",aria-orientation, andaria-controlspointing at the panel before it. aria-valuenow,aria-valueminandaria-valuemaxare fractions from 0 to 1.
Focus
Keyboard focus draws the handle line 2px wide in --cui-focus-color, with no transition.
SSR notes
Panels with fractional sizes render at their size on the server. A pixel initialSize needs the measured root, so prefer fractions when the first server paint matters.
Theming hooks
Set these on the handle. See Tokens for the defaults.
| Variable | Default | Used for |
|---|---|---|
--cui-resizable-handle-size | --cui-space-2 (8px) | Hit area. It overlaps both panels, so the panels still fill the root |
--cui-resizable-handle-line-color | --cui-border-divider | Line at rest |
--cui-resizable-handle-line-active-color | --cui-surface-scroll-thumb | Line on hover and focus (data-active) |
--cui-resizable-handle-line-dragging-color | --cui-surface-scroll-thumb-hover | Line while dragging (data-dragging) |
--cui-resizable-handle-line-width | --cui-border-width (1px) | Line width; 2px on keyboard focus |
--cui-motion-duration-fast, --cui-motion-ease-out | Line colour change, 120ms |