Skip to content
WebJs
Menu

Accessible resizable panel groups and layouts with keyboard support.

One
Two
Three
import { html } from '@webjsdev/core';

export default function ResizableDemo() {
  return html`
    <ui-resizable-panel-group orientation="horizontal" class="max-w-sm rounded-lg border">
      <ui-resizable-panel default-size="50">
        <div class="flex h-[200px] items-center justify-center p-6">
          <span class="font-semibold">One</span>
        </div>
      </ui-resizable-panel>
      <ui-resizable-handle with-handle></ui-resizable-handle>
      <ui-resizable-panel default-size="50">
        <ui-resizable-panel-group orientation="vertical">
          <ui-resizable-panel default-size="25">
            <div class="flex h-full items-center justify-center p-6">
              <span class="font-semibold">Two</span>
            </div>
          </ui-resizable-panel>
          <ui-resizable-handle with-handle></ui-resizable-handle>
          <ui-resizable-panel default-size="75">
            <div class="flex h-full items-center justify-center p-6">
              <span class="font-semibold">Three</span>
            </div>
          </ui-resizable-panel>
        </ui-resizable-panel-group>
      </ui-resizable-panel>
    </ui-resizable-panel-group>
  `;
}
View Code

About

The Resizable component is built on flex shares and Pointer Events, with no library. The server renders each panel's default size, so the layout is in the first paint, and the handles follow the WAI-ARIA window splitter pattern for the keyboard.

Installation

pnpm dlx @webjsdev/ui add resizable

Usage

import '#components/ui/resizable.ts';
<ui-resizable-panel-group orientation="horizontal">
  <ui-resizable-panel>One</ui-resizable-panel>
  <ui-resizable-handle></ui-resizable-handle>
  <ui-resizable-panel>Two</ui-resizable-panel>
</ui-resizable-panel-group>

Composition

Use the following composition to build a <ui-resizable-panel-group>:

ui-resizable-panel-group
├── ui-resizable-panel
├── ui-resizable-handle
└── ui-resizable-panel

Vertical

Use orientation="vertical" for vertical resizing.

Header
Content
import { html } from '@webjsdev/core';

export default function ResizableVertical() {
  return html`
    <ui-resizable-panel-group orientation="vertical" class="min-h-[200px] max-w-sm rounded-lg border">
      <ui-resizable-panel default-size="25">
        <div class="flex h-full items-center justify-center p-6">
          <span class="font-semibold">Header</span>
        </div>
      </ui-resizable-panel>
      <ui-resizable-handle></ui-resizable-handle>
      <ui-resizable-panel default-size="75">
        <div class="flex h-full items-center justify-center p-6">
          <span class="font-semibold">Content</span>
        </div>
      </ui-resizable-panel>
    </ui-resizable-panel-group>
  `;
}
View Code

Handle

Use the with-handle attribute on <ui-resizable-handle> to show a visible handle.

Sidebar
Content
import { html } from '@webjsdev/core';

export default function ResizableHandleDemo() {
  return html`
    <ui-resizable-panel-group orientation="horizontal" class="min-h-[200px] max-w-md rounded-lg border md:min-w-[450px]">
      <ui-resizable-panel default-size="25">
        <div class="flex h-full items-center justify-center p-6">
          <span class="font-semibold">Sidebar</span>
        </div>
      </ui-resizable-panel>
      <ui-resizable-handle with-handle></ui-resizable-handle>
      <ui-resizable-panel default-size="75">
        <div class="flex h-full items-center justify-center p-6">
          <span class="font-semibold">Content</span>
        </div>
      </ui-resizable-panel>
    </ui-resizable-panel-group>
  `;
}
View Code

RTL

To enable RTL support, see the RTL configuration guide.

واحد
اثنان
ثلاثة
import { html } from '@webjsdev/core';

const translations = {
  en: {
    dir: 'ltr',
    values: {
      one: 'One',
      two: 'Two',
      three: 'Three',
    },
  },
  ar: {
    dir: 'rtl',
    values: {
      one: 'واحد',
      two: 'اثنان',
      three: 'ثلاثة',
    },
  },
  he: {
    dir: 'rtl',
    values: {
      one: 'אחד',
      two: 'שניים',
      three: 'שלושה',
    },
  },
};

export default function ResizableRtl() {
  const lang = 'ar';
  const { dir, values: t } = translations[lang];

  return html`
    <ui-resizable-panel-group orientation="horizontal" dir=${dir} lang=${lang} class="max-w-sm rounded-lg border">
      <ui-resizable-panel default-size="50">
        <div class="flex h-[200px] items-center justify-center p-6">
          <span class="font-semibold">${t.one}</span>
        </div>
      </ui-resizable-panel>
      <ui-resizable-handle with-handle></ui-resizable-handle>
      <ui-resizable-panel default-size="50">
        <ui-resizable-panel-group orientation="vertical" dir=${dir}>
          <ui-resizable-panel default-size="25">
            <div class="flex h-full items-center justify-center p-6">
              <span class="font-semibold">${t.two}</span>
            </div>
          </ui-resizable-panel>
          <ui-resizable-handle with-handle></ui-resizable-handle>
          <ui-resizable-panel default-size="75">
            <div class="flex h-full items-center justify-center p-6">
              <span class="font-semibold">${t.three}</span>
            </div>
          </ui-resizable-panel>
        </ui-resizable-panel-group>
      </ui-resizable-panel>
    </ui-resizable-panel-group>
  `;
}
View Code

API Reference

Sizes are percentages. The layout renders without JavaScript, and resizing needs it.

ui-resizable-panel-group

AttributeTypeDefault
orientation"horizontal" | "vertical""horizontal"
EventDetail
ui-layout-change{ sizes: number[] }, percentages in panel order

ui-resizable-panel

AttributeTypeDefault
default-sizenumber (percent)an equal share of what is left
min-sizenumber (percent)-
max-sizenumber (percent)-

Give every panel a default-size for an exact server-rendered first paint.

ui-resizable-handle

AttributeTypeDefault
with-handlebooleanfalse

A handle is a focusable role="separator" (the WAI-ARIA window splitter). The arrow keys across the group move it 10 points, with Left and Right swapped under dir="rtl", and Home and End move it as far as the panel before it allows.

Changelog

Element and attribute names

The elements and their attributes use these names:

NameWhat it is
<ui-resizable-panel-group>The group that lays its panels out.
<ui-resizable-panel>One panel.
<ui-resizable-handle>The separator you drag between two panels.
orientation attributeThe direction the group lays its panels out in.
default-size="50"A panel's starting size, as a percentage.
ui-layout-change eventFired with the panel sizes, as percentages, when the layout changes.
aria-orientationSet on each handle to match the group.