Resizable panel splitter with two layers of progressive enhancement: attribute init and full web component.
Overview
The splitter provides resizable panel support as a two-layer progressive enhancement story — from attribute init to full web component — matching a "platform-first, enhance upward" philosophy.
Layer 1: Attribute Init
Light JS (about 200 lines). Apply data-splitter to a container. A small init script injects a full-height drag divider between the first two children with pointer and keyboard events.
12345
<section data-layout="sidebar" data-splitter> <nav aria-label="Sidebar">Sidebar content</nav> <main>Main content</main></section>
Vertical Splitting
1234
<section data-layout="stack" data-splitter="vertical"> <section>Top panel</section> <section>Bottom panel</section></section>
Constraints and RTL
Set data-min and data-max on the first child to constrain how far the divider can move; the initial position is clamped into that range. In right-to-left containers the first panel sits on the right and drag and arrow keys mirror.
1234
<section data-layout="sidebar" data-splitter> <nav aria-label="Sidebar" data-min="20" data-max="60">Sidebar (20-60%)</nav> <main>Main content</main></section>
The attribute utility fires splitter:resize ({ position }); see data-splitter.
Keyboard
| Key | Action |
| ArrowLeft / ArrowRight | Move divider 1% in the arrow's direction (mirrored in RTL) |
| Shift + Arrow | Move divider 10% |
| Home | Move to minimum |
| End | Move to maximum |
Layer 2: Web Component
Full component. Self-contained <split-surface> element with persistence, collapsible panels, custom events, and JS API.
1234
<split-surface> <nav>Sidebar</nav> <main>Content</main></split-surface>
All Attributes
1234567891011
<split-surface direction="vertical" position="30" min="15" max="70" persist="editor-sidebar" collapsible> <aside>Panel A</aside> <section>Panel B</section></split-surface>
| Attribute | Values | Default | Description |
|---|
direction | "horizontal", "vertical" | horizontal | Split axis. Observed |
position | number | 50 | Default split position as a percentage (0–100). A persisted value wins over it on load. Observed (changes apply), not reflected: read the live value from the position property |
min | number | 10 | Minimum panel size percentage. Observed |
max | number | 90 | Maximum panel size percentage. Observed |
persist | string | — | VBStore key suffix under namespace 'layout' (vb:layout:split:{key}); stores { position, collapsed } after user resizes and wins over the position attribute on load |
collapsible | boolean | — | Enter or double-click on the divider collapses / expands the first panel (collapsed panel is inert; aria-valuemin becomes 0). Observed |
data-label-resize | string | Resize panels | Accessible name of the divider |
data-label-collapsed | string | Collapsed | Divider aria-valuetext while the first panel is collapsed (otherwise "{n}%") |
Position and persistence
position is the default split. With persist, the user’s last layout (position and collapsed state, stored under vb:layout:split:{key} after they resize) wins over position on the next load; reset() clears it and returns to position. Changing position, min, max or direction after upgrade is applied; the attribute is not reflected, so read the live value from the position property.
Collapsing
With collapsible, Enter or a double-click on the divider collapses the first panel to zero and back. While collapsed the panel is inert (its links and controls leave the tab order), the divider reports aria-valuenow="0" with aria-valuetext “Collapsed” (data-label-collapsed to translate), and any arrow, Home or End key expands it again — the keyboard is never trapped. split-surface:state(collapsed) styles the collapsed state.
Required Structure
| Element | Required | Description |
|---|
first child | yes | First panel content (the one the divider resizes and collapses) |
second child | yes | Second panel content — divider is auto-created between them |
Events
| Event | Detail | Description |
|---|
split-surface:resize | { position, source } | Fired when the split changes; source is 'pointer', 'keyboard', 'api' or 'attribute'. Not fired on initial load / reconnect |
split-surface:collapse | { collapsed, source } | Fired when the first panel is collapsed or expanded |
1234567891011
const splitter = document.querySelector('split-surface'); splitter.addEventListener('split-surface:resize', (e) => { if (e.detail.source === 'api') return; console.log('User resized to', e.detail.position);}); splitter.addEventListener('split-surface:collapse', (e) => { console.log('Collapsed:', e.detail.collapsed);});
JavaScript API
| Property / Method | Type | Description |
element.position | number | Get/set the live position (0–100, clamped to min/max; 0 while collapsed). Non-numeric values are ignored. |
element.collapsed | boolean | Get/set collapsed state |
element.reset() | method | Expand, restore the position attribute (or 50), clear persistence |
123456789
const el = document.querySelector('split-surface'); el.position = 30; console.log(el.position); el.collapsed = true; el.collapsed = false; el.reset();
The divider is created asynchronously (after the persisted layout is read), so properties and reset() set right after creating or appending the element are queued and applied once it is ready.
Keyboard Navigation
Both layers support the same keyboard controls:
| Key | Action |
| ArrowLeft / ArrowRight | Move divider 1% in the arrow's direction (side-by-side; mirrored in RTL) |
| ArrowUp / ArrowDown | Move divider 1% (stacked) |
| Shift + Arrow | Move divider 10% |
| Home | Move to minimum position |
| End | Move to maximum position |
| Enter | Collapse / expand the first panel (<split-surface collapsible> only) |
While collapsed, any arrow, Home or End key expands the panel again.
Accessibility
Separator Role
The divider has role="separator" with aria-valuenow, aria-valuemin, aria-valuemax and aria-controls (the first panel; an id is generated when missing). aria-orientation is the divider's own axis: vertical for side-by-side panels, horizontal for direction="vertical". Screen readers announce the current position; <split-surface> adds an aria-valuetext such as “30%” or “Collapsed”. When collapsible is set, aria-valuemin is 0 because the panel can reach zero.
The accessible name defaults to "Resize panels"; set data-label-resize to translate or specialise it.
Keyboard Support
The divider is focusable (tabindex="0") and responds to arrow keys. Shift + arrow provides larger steps. Home and End jump to min/max. On a collapsible <split-surface>, Enter collapses and expands, following the APG window-splitter pattern, so collapse is not mouse-only.
Forced colors
In Windows High Contrast the divider is drawn in CanvasText with a Canvas grip, and hover, drag and focus switch to Highlight, for both layers.
Touch Support
The divider uses touch-action: none and setPointerCapture for reliable pointer drag behavior across devices. A cancelled gesture (pointercancel or lost capture) ends the drag cleanly.
Styling
The divider uses the .split-divider class shared by both layers. The ::after pseudo-element renders a grip indicator.
12345678910
.split-divider { background: var(--color-interactive);} .split-divider::after { background: white; border-radius: 4px;}
Progressive Enhancement
Without JavaScript, <split-surface> renders as a simple two-column flex layout. The :not(:defined) selector provides the fallback. Once JS registers the component, the divider appears.
12345678910
split-surface:not(:defined) { display: flex; gap: var(--size-s);} split-surface:not(:defined) > * { flex: 1; min-width: 0;}
Which Layer to Choose
| Layer | JS | Keyboard | ARIA | Persistence | Best for |
data-splitter | ~200 lines | Yes | Yes | No | Enhanced layout containers with accessibility |
<split-surface> | ~430 lines | Yes | Yes | Yes | Full-featured standalone component (collapse, persistence, JS API) |