Skip to Content
CodeUI

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

Editor
Preview
resizable/basic.tsx
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

Panel
Panel

Tap a part to outline it in the demo.

  1. 01Resizableresizableclasses.root
  2. 02ResizablePanelresizable-panelclasses.panel
  3. 03ResizableHandleresizable-handleclasses.handle
ExportRendersclasses keydata-cuiRole
Resizablediv with display: flexrootresizablenone
ResizablePaneldiv with flex-basis set to its sizepanelresizable-panelnone
ResizableHandlebuttonhandleresizable-handleseparator

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

fetch-retry.ts
Console
resizable/vertical.tsx
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.

Snippets
fetch-retry.ts
resizable/sidebar.tsx
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

fetch-retry.ts
Side panel
resizable/islands.tsx
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

fetch-retry.ts
Settings
Settings is open.
resizable/collapsible.tsx
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

KeyAction
TabFocuses the handle.
← →Move a horizontal handle by keyboardDelta (0.1 of the root by default).
↑ ↓Move a vertical handle by keyboardDelta.
Shift + arrowMoves the handle as far as the panels allow.
Home EndMove the handle to the minimum or the maximum size.
EnterCollapses or expands the nearest collapsible panel.

ARIA

  • The handle has role="separator", aria-orientation, and aria-controls pointing at the panel before it.
  • aria-valuenow, aria-valuemin and aria-valuemax are 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.

VariableDefaultUsed 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-dividerLine at rest
--cui-resizable-handle-line-active-color--cui-surface-scroll-thumbLine on hover and focus (data-active)
--cui-resizable-handle-line-dragging-color--cui-surface-scroll-thumb-hoverLine 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-outLine colour change, 120ms
  • Sheet holds the same panel on a phone.
  • Stack lays out areas the user does not resize.

On this page