Skip to content

Resizable

Splits an area into panels whose sizes the user changes by dragging a handle or using the keyboard.

Orders
Order PO-2041

Installation

pnpm dlx shadcn@latest add @silkware/resizable

To copy the component by hand, install its dependencies:

pnpm add react-resizable-panels cn

Then copy the source into components/ui/resizable.tsx:

components/ui/resizable.tsx
"use client"
import { cn } from "cn"import * as ResizablePrimitive from "react-resizable-panels"
function ResizablePanelGroup({  className,  ...props}: ResizablePrimitive.GroupProps) {  return (    <ResizablePrimitive.Group      data-slot="resizable-panel-group"      className={cn(        "flex h-full w-full aria-[orientation=vertical]:flex-col",        className      )}      {...props}    />  )}
function ResizablePanel({ ...props }: ResizablePrimitive.PanelProps) {  return <ResizablePrimitive.Panel data-slot="resizable-panel" {...props} />}
function ResizableHandle({  withHandle,  className,  ...props}: ResizablePrimitive.SeparatorProps & {  withHandle?: boolean}) {  return (    <ResizablePrimitive.Separator      data-slot="resizable-handle"      className={cn(        "relative flex w-px items-center justify-center bg-border ring-offset-background after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-hidden aria-[orientation=horizontal]:h-px aria-[orientation=horizontal]:w-full aria-[orientation=horizontal]:after:left-0 aria-[orientation=horizontal]:after:h-1 aria-[orientation=horizontal]:after:w-full aria-[orientation=horizontal]:after:translate-x-0 aria-[orientation=horizontal]:after:-translate-y-1/2 [&[aria-orientation=horizontal]>div]:rotate-90",        className      )}      {...props}    >      {withHandle && (        <div className="z-10 flex h-6 w-1 shrink-0 rounded-lg bg-border" />      )}    </ResizablePrimitive.Separator>  )}
export { ResizableHandle, ResizablePanel, ResizablePanelGroup }

Usage

import {  ResizableHandle,  ResizablePanel,  ResizablePanelGroup,} from "@/components/ui/resizable"
<ResizablePanelGroup orientation="horizontal" className="min-h-48 max-w-md rounded-lg border">  <ResizablePanel defaultSize="40%" minSize="20%">    Orders  </ResizablePanel>  <ResizableHandle />  <ResizablePanel defaultSize="60%">    Order detail  </ResizablePanel></ResizablePanelGroup>

There are two things to know before you start:

  • Sizes are strings or numbers, and they mean different things. A string such as "40%" is a percentage, a bare number such as 40 is pixels. Use strings.
  • The group sets its own width and height to 100% of its parent. Limit it with min-h-* and max-w-*, or give its parent a size. A h-48 or w-64 class on the group is overridden.

Examples

Horizontal

Panels side by side, split by a vertical handle. This is the default orientation.

Orders
Order PO-2041

Vertical

orientation="vertical" stacks the panels and uses a horizontal handle.

Summary
Order lines

With handle

withHandle adds a small grip to the handle so the user sees that it can be dragged. Use it when the handle is the only sign that the layout is adjustable.

Bergamo
Brescia

Nested

Put a group inside a panel to split one region again in the other direction.

Suppliers
Tornival
Open orders

Collapsible

collapsible lets a panel fold away when dragged below minSize, down to collapsedSize. Drag the handle left, or press Enter on it, to fold the filters.

Filters
Deliveries

Accessibility

KeyAction
TabMoves focus to the next handle.
ArrowLeftMoves a vertical handle left and shrinks the panel before it. A horizontal handle ignores it.
ArrowRightMoves a vertical handle right and grows the panel before it. A horizontal handle ignores it.
ArrowUpMoves a horizontal handle up and shrinks the panel above it. A vertical handle ignores it.
ArrowDownMoves a horizontal handle down and grows the panel above it. A vertical handle ignores it.
HomeShrinks the panel before the handle to its minimum size.
EndGrows the panel before the handle to its maximum size.
EnterCollapses or expands the panel, when the panel is collapsible.

react-resizable-panels provides:

  • A separator role on each handle, with aria-orientation, aria-valuenow, aria-valuemin, aria-valuemax and aria-controls for the panel it resizes.
  • Pointer and touch dragging, and the keyboard resizing above.
  • Size limits that hold for every input method.

You provide:

  • An aria-label on a handle when the purpose of the split is not obvious from the panels.
  • Content that works at the minimum size: set minSize so labels are not cut.
  • Another way to reach content in a collapsible panel, such as a button, because a folded panel has no width, so its content cannot be seen.

Guidelines

When to use

  • When users work with two or more areas at once and need different sizes at different times: a list beside a detail view, a table above a preview.
  • In desktop tools that have room to share.

When not to use

  • For a layout that never needs to change. Use a normal layout, or a Sidebar with a fixed width.
  • To show and hide a block. Use a Collapsible.
  • On small screens. A split of 375px leaves each panel unusable. Stack the content instead.

Content

  • Set minSize on every panel so content stays readable.
  • Use maxSize when one panel must not take over.
  • Let each panel scroll on its own with a Scroll Area.
Orders
Detail
Do

Write sizes as percentage strings and set a minimum.

Orders
Detail
Don’t

Don’t pass a bare number. 30 is 30 pixels, so the panel collapses to a sliver.

API reference

ResizablePanelGroup

The container. Renders a div through the Group of react-resizable-panels, as a flex row, or a column when vertical. It accepts every Group prop.

PropTypeDefaultDescription
orientation?"horizontal" | "vertical""horizontal"The direction in which panels are laid out and resized.
defaultLayout?Record<string, number>NoneThe sizes of the panels by panel id, for example to restore a saved layout.
onLayoutChange?(layout: Record<string, number>) => voidNoneCalled while the layout changes.
onLayoutChanged?(layout: Record<string, number>) => voidNoneCalled after the layout has changed, for example to save it.
disabled?booleanfalsePrevents resizing of the whole group.
className?stringNoneClasses merged after the base classes.

ResizablePanel

One panel. Renders a div through the Panel of react-resizable-panels.

PropTypeDefaultDescription
id?stringNoneIdentifies the panel in layouts. Needed when you save and restore sizes.
defaultSize?number | stringNoneThe size at first. A string is a percentage, a number is pixels.
minSize?number | stringNoneThe smallest size. A string is a percentage, a number is pixels.
maxSize?number | stringNoneThe largest size. A string is a percentage, a number is pixels.
collapsible?booleanfalseLets the panel fold to collapsedSize when it is dragged below minSize.
collapsedSize?number | stringNoneThe size of the panel when it is collapsed.
disabled?booleanfalsePrevents resizing of this panel.
onResize?(size: PanelSize, id: string | number | undefined, prevSize: PanelSize | undefined) => voidNoneCalled when the panel size changes. PanelSize holds asPercentage and inPixels.

ResizableHandle

The divider between two panels. Renders a div with the separator role through the Separator of react-resizable-panels.

PropTypeDefaultDescription
withHandle?booleanfalseShows a grip in the middle of the handle.
disabled?booleanfalsePrevents dragging this handle.
className?stringNoneClasses merged after the base classes.