Skip to content

Resizable

Panels side by side (or stacked) with handles you drag to share the space between them. The handles work from the keyboard too. Same markup and props in every style: switch the style in the header to see it change.

Horizontal

A sidebar and a main area. Drag the handle, or Tab to it and use the arrow keys. In HTML, add data-vin-resizable and include vinui.js.

Mailboxes

Inbox
Drafts
Sent
Archive

Inbox

Drag the handle to give the list more room, or Tab to it and use the arrow keys.

resizable-horizontal.html
<div class="vin-resizable" style="width: 100%; max-width: 520px; height: 200px" data-vin-resizable>
  <div class="vin-resizable__panel" id="rz-sidebar" style="--vin-size: 30" data-min="20">
    <div style="padding: 16px">
      <p style="margin: 0 0 8px; font-weight: 600">Mailboxes</p>
      <p style="margin: 0; color: var(--vin-muted)">Inbox<br>Drafts<br>Sent<br>Archive</p>
    </div>
  </div>
  <div class="vin-resizable__handle vin-resizable__handle--grip" role="separator" tabindex="0" aria-label="Resize mailboxes" aria-controls="rz-sidebar" aria-orientation="vertical" aria-valuenow="30" aria-valuemin="20" aria-valuemax="70"></div>
  <div class="vin-resizable__panel" style="--vin-size: 70" data-min="30">
    <div style="padding: 16px">
      <p style="margin: 0 0 8px; font-weight: 600">Inbox</p>
      <p style="margin: 0; color: var(--vin-muted)">Drag the handle to give the list more room, or Tab to it and use the arrow keys.</p>
    </div>
  </div>
</div>

Vertical

An editor above a terminal. Up and Down move the handle; Enter folds the editor away and brings it back.

export function greet(name) {
  return `Hello, ${name}!`;
}
$ npm run dev
Ready on http://localhost:4321
resizable-vertical.html
<div class="vin-resizable vin-resizable--vertical" style="width: 100%; max-width: 420px; height: 260px" data-vin-resizable>
  <div class="vin-resizable__panel" id="rz-editor" style="--vin-size: 60" data-min="15">
    <pre style="margin: 0; padding: 12px 16px; font: 13px/1.6 ui-monospace, monospace">export function greet(name) {
  return `Hello, ${name}!`;
}</pre>
  </div>
  <div class="vin-resizable__handle vin-resizable__handle--grip" role="separator" tabindex="0" aria-label="Resize editor" aria-controls="rz-editor" aria-orientation="horizontal" aria-valuenow="60" aria-valuemin="15" aria-valuemax="85"></div>
  <div class="vin-resizable__panel" style="--vin-size: 40" data-min="15">
    <pre style="margin: 0; padding: 12px 16px; font: 13px/1.6 ui-monospace, monospace; color: var(--vin-muted)">$ npm run dev
Ready on http://localhost:4321</pre>
  </div>
</div>

Nested

A group inside a panel: three areas, each with a minimum size so none disappears.

Files
Preview
Console
resizable-nested.html
<div class="vin-resizable" style="width: 100%; max-width: 560px; height: 260px" data-vin-resizable>
  <div class="vin-resizable__panel" id="rz-files" style="--vin-size: 25" data-min="15">
    <div style="padding: 16px; font-weight: 600">Files</div>
  </div>
  <div class="vin-resizable__handle" role="separator" tabindex="0" aria-label="Resize files" aria-controls="rz-files" aria-orientation="vertical" aria-valuenow="25" aria-valuemin="15" aria-valuemax="70"></div>
  <div class="vin-resizable__panel" style="--vin-size: 75" data-min="30">
    <div class="vin-resizable vin-resizable--vertical" data-vin-resizable>
      <div class="vin-resizable__panel" id="rz-preview" style="--vin-size: 65" data-min="20">
        <div style="padding: 16px; font-weight: 600">Preview</div>
      </div>
      <div class="vin-resizable__handle" role="separator" tabindex="0" aria-label="Resize preview" aria-controls="rz-preview" aria-orientation="horizontal" aria-valuenow="65" aria-valuemin="20" aria-valuemax="80"></div>
      <div class="vin-resizable__panel" style="--vin-size: 35" data-min="20">
        <div style="padding: 16px; font-weight: 600">Console</div>
      </div>
    </div>
  </div>
</div>

Installation

React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:

Terminal
npx @vinish/ui add resizable
React
import { ResizableGroup, ResizablePanel, ResizableHandle } from "@/components/vin/resizable";
Vue
import ResizableGroup, { ResizablePanel, ResizableHandle } from "@/components/vin/resizable.vue";
Svelte
import ResizableGroup from "$lib/components/vin/resizable.svelte";
import ResizableHandle from "$lib/components/vin/resizable-handle.svelte";
import ResizablePanel from "$lib/components/vin/resizable-panel.svelte";

The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.

Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.

API

From spec/resizable.json, which every framework version is tested against.

PropValuesDefaultIn HTML
orientation
Group: panels side by side, or stacked.
horizontalverticalhorizontalvin-resizable--vertical
onLayout
Group: called with every panel's size (percent) after a change.
(sizes: number[]) => void—a vin-resize event on .vin-resizable, with detail.sizes
defaultSize
Panel: its starting size, in percent of the group. Panels without one share what is left.
number—style="--vin-size: 30" on .vin-resizable__panel
minSize
Panel: the smallest it can get, in percent. Enter on a handle collapses the panel before it to this size.
number10data-min="20" on .vin-resizable__panel
label
Handle: what it resizes, for screen readers.
string"Resize"aria-label on .vin-resizable__handle
withGrip
Handle: draw a small grip in the middle of the line.
booleanfalsevin-resizable__handle--grip

Parts

React, Vue, SvelteHTML classes
<ResizableGroup><ResizablePanel><ResizableHandle>.vin-resizable.vin-resizable--vertical.vin-resizable__panel.vin-resizable__handle.vin-resizable__handle--grip

Accessibility

  • Each handle follows the WAI-ARIA window splitter pattern: role="separator" with tabindex="0", aria-valuenow (the size of the panel before it, in percent), aria-valuemin, aria-valuemax and aria-controls pointing at that panel.
  • A handle between side-by-side panels has aria-orientation="vertical" and moves with Left and Right; between stacked panels it is horizontal and moves with Up and Down.
  • Home and End move to the smallest and largest size; Enter collapses the panel before it to its minimum, and Enter again puts it back.
  • Each handle has a name (aria-label) that says what it resizes, and a visible focus style in every style and mode.
  • The grab area is wider than the 1px line, so it is easy to hit with a mouse or a finger.