Adjustable workspace with a readable mobile fallback
Resize the list and inspector by pointer or keyboard. Collapse and restore the inspector; the host stores committed layouts, and narrow screens show both panels in order.
Keyboard
- Tab to the separator. Left and Right adjust by two percent; Shift adjusts by ten.
- Home and End move to the allowed limits. Enter collapses or restores the adjacent inspector.
- Pointer dragging follows the pointer directly. Escape cancels an active drag.
- Scroll regions enter the tab order only when their content overflows. Native arrow-key and touch scrolling remain available.
States covered
- pointer and touch resize
- keyboard constraints
- collapse and restore
- controlled layout
- host persistence
- mobile stack
- reduced motion
- native scroll regions
Install this complete example and its component dependencies.
npx shadcn@latest add https://ui.bld8.dev/r/example-resizable-workspace-panes.jsonComplete source
/*!
MIT License
Copyright (c) 2026 Jaison
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import '@bld8/ui/styles.css';
import { useEffect, useState } from 'react';
import { Checkbox, ResizablePanels, ScrollArea, UIProvider, normalizePanelLayout, type PanelLayout } from '@bld8/ui';
const constraints = [{ id: 'records', label: 'Records', minSize: 30, maxSize: 100, defaultSize: 65 }, { id: 'inspector', label: 'Inspector', minSize: 15, maxSize: 70, defaultSize: 35, collapsible: true }];
export default function ResizableWorkspaceExample() {
const [layout, setLayout] = useState<PanelLayout>(() => normalizePanelLayout(constraints)), [status, setStatus] = useState('Drag the divider or use its keyboard controls.'), [disabled, setDisabled] = useState(false);
useEffect(() => { try { const saved = localStorage.getItem('workspace-example-layout'); if (saved) setLayout(normalizePanelLayout(constraints, JSON.parse(saved))); } catch { /* Ignore stale or unavailable host storage. */ } }, []);
return <UIProvider><div style={{ minWidth: 0 }}><Checkbox label="Disable resizing" checked={disabled} onCheckedChange={setDisabled}/><ResizablePanels disabled={disabled} label="Workspace panels" layout={layout} onLayoutChange={setLayout}
onLayoutCommit={next => { try { localStorage.setItem('workspace-example-layout', JSON.stringify(next)); setStatus('Panel layout saved by this example.'); } catch { setStatus('Layout changed. Browser storage is unavailable.'); } }}
panels={constraints.map(panel => ({ ...panel, children: <div style={{ padding: 20, background: 'var(--bui-surface)', borderRadius: 6 }}><h3>{panel.label}</h3><ScrollArea label={panel.label + ' content'} style={{ height: 280 }}><div style={{ display: 'grid', gap: 14 }}>{Array.from({ length: panel.id === 'records' ? 24 : 10 }, (_, index) => <p key={index}>{panel.id === 'records' ? 'Record ' + (index + 1) + ' — review keyboard focus and field spacing.' : 'Inspector detail ' + (index + 1) + '. The host owns the selected record.'}</p>)}</div></ScrollArea></div> }))}/>
<p role="status" className="bui-hint">{status}</p><output aria-label="Current panel layout">{JSON.stringify(layout)}</output>
</div></UIProvider>;
}