affectUI › Components › Data display

Resizable

Panes side by side or stacked with a line between them you can drag – sizes in percent, a smallest and largest size, panes that fold away, arrow keys, Home, End and Enter on the handle, a double-click to reset.

Free and open source (MIT). Install: npx shadcn@latest add https://www.affectui.com/r/resizable.json · Import from @/components/ui/resizable

When to use

  • A sidebar or list next to a work area that people want wider or narrower: runs and their output, files and an editor, a thread and its detail
  • An editor over its output or log, stacked – nest a vertical group inside a pane
  • A pane that should fold away and come back – collapsible, with Enter on its handle or a drag past half its minimum

When not to use

  • Two views the user switches between rather than sees together – use tabs or the Segmented Control
  • A panel that slides over the page for a moment – use the Dialog or the Popover
  • Only scrolling inside a fixed box – use the Scroll Area (and put one inside each pane when its content is long)

Usage

import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "@/components/ui/resizable";

export function Workspace() {
  return (
    <div style={{ height: 480 }}>
      <ResizablePanelGroup direction="horizontal" onLayout={(sizes) => localStorage.setItem("workspace", JSON.stringify(sizes))}>
        <ResizablePanel defaultSize={30} minSize={20} maxSize={50} collapsible>
          <RunList />
        </ResizablePanel>
        <ResizableHandle withHandle aria-label="Resize the runs list" />
        <ResizablePanel defaultSize={70} minSize={40}>
          <ResizablePanelGroup direction="vertical">
            <ResizablePanel defaultSize={65}>
              <RunOutput />
            </ResizablePanel>
            <ResizableHandle aria-label="Resize the log" />
            <ResizablePanel defaultSize={35} minSize={15} collapsible>
              <RunLog />
            </ResizablePanel>
          </ResizablePanelGroup>
        </ResizablePanel>
      </ResizablePanelGroup>
    </div>
  );
}

Props

NameTypeDefaultDescription
ResizablePanelGroup · direction"horizontal" | "vertical""horizontal"horizontal: panes side by side · vertical: stacked. The group fills its parent – give the parent a height
ResizablePanelGroup · onLayout(sizes: number[]) => voidEvery pane's size in %, in order, after the user resizes – store it and pass it back as defaultSize
ResizablePanelGroup · keyboardStepnumber5How far an arrow key moves a handle, in %; Shift doubles it
ResizablePanel · defaultSizenumberThe size it starts at, in %. Panes without one share what is left; all sizes are scaled to add up to 100
ResizablePanel · minSize / maxSizenumber0 / 100Its smallest and largest size, in %
ResizablePanel · collapsiblebooleanfalseSnaps to collapsedSize when dragged past half its minimum; Enter on the handle next to it folds it and brings it back
ResizablePanel · collapsedSizenumber0Its size when folded, in %. At 0 it is hidden and inert; a little more keeps an icon rail
ResizableHandle · withHandlebooleanfalseA small grip on the line, so it reads as draggable
ResizableHandle · aria-labelstring"Resize"What it resizes, read out by screen readers – e.g. "Resize the runs list"
...div propsComponentProps<"div">className, style, id, ref … go to the group, the pane or the handle

Keyboard

  • Tab: Reaches each handle
  • ← / →: Move a handle between panes side by side (↑ ↓ for stacked ones); Shift moves twice as far
  • Home / End: Make the pane before the handle as small or as large as it may get
  • Enter: Fold the collapsible pane next to the handle, or bring it back to its size

Accessibility

  • Each handle is a focusable role="separator" with aria-valuenow, aria-valuemin and aria-valuemax – the size of the pane before it in % – and aria-controls pointing at that pane
  • Name each handle with aria-label, so screen readers say what it resizes
  • A pane folded to 0 is inert: its controls leave the Tab order and screen readers skip it
  • The focus ring is drawn around the grab strip, inside it, so the panes never cut it; only on keyboard focus

Responsive

  • Sizes are in %, so the layout keeps its proportions at any width; a pane's content never pushes it wider – it scrolls
  • A 12px grab strip over the line (24px on touch screens) and a bigger grip on touch
  • Right to left: the panes and the arrow keys follow the reading direction
  • Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"

Requirements

  • React 19

Related

  • Scroll Area – A box that scrolls the browser's own way with a slim scrollbar of its own – it shows on hover and while scrolling, a draggable thumb, up and down or sideways, soft fades where there is more
  • Separator – A thin line between groups – across or upright between tools, an optional word in its middle like "or" or "Earlier", decorative or a real separator for screen readers
  • Data Table – Spreadsheet-style table: select cells and ranges, edit in place, copy and paste, undo and sort
  • Dialog – A modal window on a dimmed backdrop – title and quiet line, content that scrolls under a fixed header and footer, Escape and backdrop close, the focus kept inside and handed back, a sheet on phones, and an AlertDialog to confirm with a red button