---
title: "Resizable"
description: "Accessible resizable panels with horizontal, vertical and right-to-left layouts."
---

# Resizable

Accessible resizable panels with horizontal, vertical and right-to-left layouts.

## Installation

Install the shared package once in your Exact app. This version is a beta.

```sh
bun add --exact @rightui/ui@0.4.0-beta.4
```

Or choose another package manager:

```sh
npm install --save-exact @rightui/ui@0.4.0-beta.4
pnpm add --save-exact @rightui/ui@0.4.0-beta.4
yarn add --exact @rightui/ui@0.4.0-beta.4
```

Exact compilation uses Bun 1.4.2. Register Geist and Newsreader, declare the font marker and add the root provider using [Installation](/docs/installation).

### Manual source setup

Install an editable copy of the complete package:

```sh
mkdir -p vendor/rightui vendor/rightui-ui
npm pack @rightui/ui@0.4.0-beta.4 --pack-destination vendor/rightui
tar -xzf ./vendor/rightui/rightui-ui-0.4.0-beta.4.tgz -C vendor/rightui-ui --strip-components=1
bun add file:./vendor/rightui-ui
```

Keep package.json, the Contract files, ui.tamber, assets and licenses together.

### Import

```contract
use ResizablePanelGroup, ResizablePanel, ResizableHandle from "@rightui/ui"
```

## Usage

Compose ResizablePanelGroup, ResizablePanel and ResizableHandle. Set orientation to horizontal or vertical, dir to ltr or rtl, and withHandle to show or hide the grip. Pass the same orientation and dir to the group and its handle. Store the first panel percentage in state and update it with change. Each example has independent state.

## Example

```contract
use FontWeights from "@rightui/ui"
use uiFontFamily, Input, Switch, ResizablePanelGroup, ResizablePanel, ResizableHandle from "@rightui/ui"

component Demo
  props
    width: number
    reduced: bool
  inject
    uiWeights: FontWeights
    uiFont: string
  derive narrow = width < 600
  state horizontal = 32
  state vertical = 58
  state draft = "My edit"
  action changeHorizontal(v: number)
    horizontal = v
  action changeVertical(v: number)
    vertical = v
  action editDraft(v: string)
    draft = v
  view
    column gap="ui.space-24" min-width=0 max-width="100%" box-sizing="border-box"
      DemoPanels(id="resizable-horizontal", title="Horizontal", orientation="horizontal", initialDir="ltr", initialHandle=false, disabled=false, reduced=reduced)
      DemoPanels(id="resizable-vertical", title="Vertical", orientation="vertical", initialDir="ltr", initialHandle=false, disabled=false, reduced=reduced)
      DemoPanels(id="resizable-handle", title="With handle", orientation="horizontal", initialDir="ltr", initialHandle=true, disabled=false, reduced=reduced)
      DemoPanels(id="resizable-rtl", title="RTL", orientation="horizontal", initialDir="rtl", initialHandle=true, disabled=false, reduced=reduced)
      text "Nested panels" font-size="ui.text-base" font-weight=uiWeights.semibold font-family=uiFontFamily(uiFont) data-rightui-font="body"
      view height=360 width="100%" box-sizing="border-box" border-width="ui.border-width" border-style="solid" border-color="ui.border" border-radius="ui.radius-md"
        ResizablePanelGroup(id="split-horizontal", orientation="horizontal", dir="ltr", value=horizontal)
          ResizablePanel(id="split-sidebar", label="Library", minContentWidth="7rem")
            text "Library" font-size="ui.text-sm" font-weight=uiWeights.semibold color="ui.foreground" hyphens="auto" font-family=uiFontFamily(uiFont) data-rightui-font="body"
            for item in ["Project", "Media", "Music", "Exports"] key=item
              text item font-size="ui.text-caption" color="ui.muted-foreground" hyphens="auto" font-family=uiFontFamily(uiFont) data-rightui-font="body"
          ResizableHandle(id="split-x", groupId="split-horizontal", primaryId="split-sidebar", label="Library width", orientation="horizontal", dir="ltr", value=horizontal, minimum=20, maximum=65, reset=32, withHandle=true, disabled=false, change=changeHorizontal)
          ResizablePanelGroup(id="split-vertical", orientation="vertical", dir="ltr", value=vertical)
            ResizablePanel(id="split-editor", label="Editor", minContentWidth="7rem")
              text "Editor" font-size="ui.text-sm" font-weight=uiWeights.semibold color="ui.foreground" font-family=uiFontFamily(uiFont) data-rightui-font="body"
              Input(id="split-name", label="Name", value=draft, placeholder="Your project", error="", disabled=false, edit=editDraft)
            ResizableHandle(id="split-y", groupId="split-vertical", primaryId="split-editor", label="Editor height", orientation="vertical", dir="ltr", value=vertical, minimum=25, maximum=75, reset=58, withHandle=true, disabled=false, change=changeVertical)
            ResizablePanel(id="split-timeline", label="Timeline", minContentWidth="7rem")
              text "Timeline" font-size="ui.text-sm" font-weight=uiWeights.semibold color="ui.foreground" font-family=uiFontFamily(uiFont) data-rightui-font="body"
              text draft testId="split-echo" font-size="ui.text-caption" color="ui.muted-foreground" hyphens="auto" font-family=uiFontFamily(uiFont) data-rightui-font="body"
              view height="ui.space-24" border-radius="ui.radius-inline" background-color="ui.ring"
      DemoPanels(id="variation-resize-disabled", title="Disabled", orientation="horizontal", initialDir="ltr", initialHandle=true, disabled=true, reduced=reduced)

component DemoPanels
  props
    id: string
    title: string
    orientation: string
    initialDir: string
    initialHandle: bool
    disabled: bool
    reduced: bool
  inject
    uiWeights: FontWeights
    uiFont: string
  state ratio = 50
  state rtl = initialDir == "rtl"
  state handle = initialHandle
  action resize(value: number)
    ratio = value
  action changeRtl(value: bool)
    rtl = value
  action changeHandle(value: bool)
    handle = value
  view
    column gap="ui.space-12" min-width=0
      text title font-size="ui.text-base" font-weight=uiWeights.semibold font-family=uiFontFamily(uiFont) data-rightui-font="body"
      if id == "resizable-handle"
        Switch(id=id + "-toggle", label="withHandle", checked=handle, disabled=false, reduced=reduced, change=changeHandle)
      if id == "resizable-rtl"
        Switch(id=id + "-toggle", label="Right to left", checked=rtl, disabled=false, reduced=reduced, change=changeRtl)
      view height=200 width="100%" box-sizing="border-box" border-width="ui.border-width" border-style="solid" border-color="ui.border" border-radius="ui.radius-md"
        ResizablePanelGroup(id=id, orientation=orientation, dir=(rtl ? "rtl" : "ltr"), value=ratio)
          ResizablePanel(id=id + "-first", label="First panel", minContentWidth="0px")
            text (rtl ? "واحد" : "One") font-size="ui.text-sm" font-weight=uiWeights.semibold font-family=uiFontFamily(uiFont) data-rightui-font="body"
          ResizableHandle(id=id + "-handle", groupId=id, primaryId=id + "-first", label="Resize panels", orientation=orientation, dir=(rtl ? "rtl" : "ltr"), value=ratio, minimum=20, maximum=80, reset=50, withHandle=handle, disabled=disabled, change=resize)
          ResizablePanel(id=id + "-second", label="Second panel", minContentWidth="0px")
            text (rtl ? "اثنان" : "Two") font-size="ui.text-sm" font-weight=uiWeights.semibold font-family=uiFontFamily(uiFont) data-rightui-font="body"
      text (ratio.toFixed(0) + "% / " + (100 - ratio).toFixed(0) + "%") testId=(id + "-value") font-size="ui.text-xs" color="ui.muted-foreground" font-family=uiFontFamily(uiFont) data-rightui-font="body"

```

## Keyboard

Arrow keys resize by 1%; Shift + Arrow resizes by 10%. Horizontal arrows follow the visual direction in RTL. Home/End select the bounds, Enter restores the initial size and Escape cancels an active drag. A hidden grip remains draggable and keyboard accessible.

## API Reference

| Property | Type |
| --- | --- |
| ResizablePanelGroup.id | string |
| ResizablePanelGroup.orientation | string |
| ResizablePanelGroup.dir | string |
| ResizablePanelGroup.value | number |
| ResizablePanel.id | string |
| ResizablePanel.label | string |
| ResizablePanel.minContentWidth | string |
| ResizableHandle.id | string |
| ResizableHandle.groupId | string |
| ResizableHandle.primaryId | string |
| ResizableHandle.label | string |
| ResizableHandle.orientation | string |
| ResizableHandle.dir | string |
| ResizableHandle.value | number |
| ResizableHandle.minimum | number |
| ResizableHandle.maximum | number |
| ResizableHandle.reset | number |
| ResizableHandle.withHandle | bool |
| ResizableHandle.disabled | bool |
| ResizableHandle.change | action |

## Source

File: packages/ui/resizable.contract

```contract
component ResizablePanelGroup
  props
    id: string
    orientation: string
    dir: string
    value: number
  slot
  derive ratio = max(0, min(100, value))
  derive tracks = "minmax(0, " + ratio.toString() + "fr) auto minmax(0, " + (100 - ratio).toString() + "fr)"
  view
    view id=id testId=id display="grid" width="100%" height="100%" min-width="0px" min-height="0px" direction=(dir == "rtl" ? "rtl" : "ltr")
      grid-template-columns=(orientation == "horizontal" ? tracks : "minmax(0, 1fr)")
      grid-template-rows=(orientation == "vertical" ? tracks : "minmax(0, 1fr)")
      children

component ResizablePanel
  props
    id: string
    label: string
    minContentWidth: string
  slot
  view
    column id=id testId=id role="group" aria-label=label min-width="0px" min-height="0px" padding="ui.space-20" box-sizing="border-box"
      scroll id=(id + "-scroll") testId=(id + "-scroll") aria-label=label flex=1 min-width="0px" min-height="0px" overflow="auto" tabindex=0
        :focus-visible
          box-shadow="ui.shadow-focus-inset"
        column gap="ui.space-12" min-width=minContentWidth width="100%" box-sizing="border-box"
          children

component ResizableHandle
  props
    id: string
    groupId: string
    primaryId: string
    label: string
    orientation: string
    dir: string
    value: number
    minimum: number
    maximum: number
    reset: number
    withHandle: bool
    disabled: bool
    change: action
  state pointer = -1
  state origin = 0
  state start = 0
  state extent = 1
  derive reverse = orientation == "horizontal" and dir == "rtl"
  derive low = max(0, min(100, minimum))
  derive high = max(low, min(100, maximum))
  action begin(e: PointerEvent)
    if not disabled and e.button == 0 and pointer == -1
      stopPropagation()
      preventDefault()
      let bounds = frame(groupId)
      let divider = frame(id + "-track")
      pointer = e.pointerId
      origin = value
      start = (orientation == "horizontal" ? e.clientX : e.clientY)
      extent = max(1, (orientation == "horizontal" ? bounds.width - divider.width : bounds.height - divider.height))
      if e.pointerType == "mouse"
        focus(id)
  action move(e: PointerEvent)
    if not disabled and e.pointerId == pointer
      stopPropagation()
      let distance = (orientation == "horizontal" ? e.clientX : e.clientY) - start
      change(max(low, min(high, origin + distance / extent * 100 * (reverse ? -1 : 1))))
  action end(e: PointerEvent)
    if e.pointerId == pointer
      stopPropagation()
      pointer = -1
  action keys(k: string, e: KeyboardEvent)
    if not disabled
      if k == "Escape" and pointer != -1
        preventDefault()
        pointer = -1
        change(origin)
      else if k == "Home" or k == "End" or k == "Enter"
        preventDefault()
        change(k == "Home" ? low : k == "End" ? high : max(low, min(high, reset)))
      else if (orientation == "horizontal" and (k == "ArrowLeft" or k == "ArrowRight")) or (orientation == "vertical" and (k == "ArrowUp" or k == "ArrowDown"))
        preventDefault()
        let delta = (k == "ArrowLeft" or k == "ArrowUp" ? -1 : 1) * (e.shiftKey ? 10 : 1)
        change(max(low, min(high, value + delta * (reverse ? -1 : 1))))
  view
    view id=(id + "-track") width=(orientation == "horizontal" ? "ui.border-width" : "100%") height=(orientation == "vertical" ? "ui.border-width" : "100%") position="relative" z-index=2 min-width="0px" min-height="0px" touch-action="none" user-select="none"
      cursor=(disabled ? "default" : orientation == "horizontal" ? "col-resize" : "row-resize")
      pointerdown=begin pointermove=move pointerup=end
      view position="absolute" pointer-events="none" background-color="ui.border"
        width=(orientation == "horizontal" ? "ui.border-width" : "100%") height=(orientation == "horizontal" ? "100%" : "ui.border-width")
        left="0px" top="0px"
      button id=id testId=id role="separator" aria-label=label aria-controls=primaryId
        aria-orientation=(orientation == "horizontal" ? "vertical" : "horizontal")
        aria-valuemin=low aria-valuemax=high aria-valuenow=value aria-valuetext=(value.toFixed(0) + " %") disabled=disabled
        key=keys pointerdown=begin pointermove=move pointerup=end
        position="absolute" z-index=2 left="50%" top="50%" translate="-50% -50%" width=(orientation == "horizontal" ? "ui.space-12" : "100%") height=(orientation == "horizontal" ? "100%" : "ui.space-12")
        appearance="none" padding="0px" border="0" background-color="transparent" touch-action="none" user-select="none"
        cursor=(disabled ? "default" : orientation == "horizontal" ? "col-resize" : "row-resize")
        display="flex" align-items="center" justify-content="center" border-radius="ui.radius-control"
        :focus-visible
          box-shadow="ui.shadow-focus"
        :disabled
          opacity="ui.opacity-disabled"
        if withHandle
          view id=(id + "-grip") testId=(id + "-grip") width=(orientation == "horizontal" ? "ui.space-12" : "ui.space-16") height=(orientation == "horizontal" ? "ui.space-16" : "ui.space-12")
            border-width="ui.border-width" border-style="solid" border-color="ui.border" border-radius="ui.radius-detail" background-color="ui.border"
            display="flex" align-items="center" justify-content="center" pointer-events="none"
            svg width="ui.space-10" height="ui.space-10" viewBox="0 0 10 16" fill="ui.muted-foreground" aria-hidden=true rotate=(orientation == "horizontal" ? "0deg" : "90deg")
              circle cx=3 cy=4 r=1
              circle cx=7 cy=4 r=1
              circle cx=3 cy=8 r=1
              circle cx=7 cy=8 r=1
              circle cx=3 cy=12 r=1
              circle cx=7 cy=12 r=1

```
