This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
SidePanel
Main content with a panel beside it, which docks when there is room and slides over when there is not — the list-and-detail layout: click a row, its detail opens alongside; click the next row, the detail swaps in place.
Wide (the component's own width at or above dockAt), the panel is docked: it sits in the page flow and the main content narrows to make room, so nothing is covered. It is not modal — no backdrop, no focus trap, no scroll lock, and clicking or typing in the main content leaves it open. It is a named complementary landmark, it does not take focus when it opens, and it closes only when asked: its close button, Escape while focus is inside it, or open = false. Opening and closing animate its width. Narrow, it is a Sheet: role="dialog" aria-modal, portalled to <body>, focus moved in and trapped and given back on close, the page inert, body scroll locked, Escape and a backdrop click to close. It measures its own box, not the window, so a layout with a sidebar of its own docks only where the content really has the room. Resizing across dockAt while open keeps it open and moves without animating: focus that was in the panel follows it into the other mode. Before hydration there is no box to measure, so the server render guesses from the viewport: an open panel is drawn docked on a wide screen and not at all on a narrow one, where it would only have squeezed the page.
Overlays · two-way: bind:open · portalled to <body> · keyboard contract
<script lang="ts">
import { SidePanel } from '@l4st/driftwood';
</script>
| Light | Dark |
|---|---|
![]() |
![]() |
![]() |
![]() |
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
open bind: |
boolean |
false |
Shows the panel: docked beside the content when wide, sliding over it when narrow. |
side |
'left' | 'right' |
'right' |
Which side of the content the panel sits on, and slides in from. |
width |
string |
'24rem' |
Any CSS length: the docked panel's width, and the most the sliding one takes (below it, it fills the screen). |
dockAt |
number |
1024 |
The component's own width in px at and above which the panel docks; below it, it slides over. |
title |
string |
— | Shown in the panel's header and names it for assistive tech (aria-labelledby). |
aria-label |
string |
— | Names the panel when there is no visible title — the landmark and the dialog need a name either way. |
closeLabel |
string |
'Close' |
Accessible name of the close button. |
class |
string |
— | Classes for the root, the flex row that holds the content and the docked panel. Give it a height to scroll the two columns separately. |
classes |
Classes<SidePanelPart> |
— | Classes for the parts inside: main (the content's column), dock (the docked panel's width-animating column and its border), overlay (the dimmed backdrop when narrow), positioner (the full-screen layer that places the sliding panel), panel (the panel itself, in either mode — docked it is sticky at top-0, so a sticky app header wants top-14 max-h-[calc(100dvh-3.5rem)] here), header (title, your header content and the × button), title, close, closeIcon, body (the scrolling part). Merged last, so they win. |
onOpenChange |
(open: boolean) => void |
— | Fires when the panel closes itself — the × button, Escape, the backdrop — with false. |
panel required |
Snippet |
— | The panel's content. Swapping what it shows while open (another row's detail) neither closes nor re-animates it. |
header |
Snippet |
— | More in the header row after the title — a badge, an action. |
children required |
Snippet |
— | The main content. |
Keyboard
| Key | Does |
|---|---|
| Escape | from inside the panel, close it; focus returns to what had it before |
| Tab / Shift+Tab | docked: moves through the page as usual. Sliding over: cycles within the panel — focus is trapped |
Example
The markup behind the screenshot above, lifted from src/routes/shots/ — so it
compiles, and it is exactly what produced the image.
<script lang="ts">
import { SidePanel, Badge, Button, Table } from '$lib/index.js';
const services = [
{ id: 'media', name: 'Media server', state: 'Running', port: 8096 },
{ id: 'backup', name: 'Backup agent', state: 'Running', port: 8200 },
{ id: 'sync', name: 'File sync', state: 'Stopped', port: 8384 },
{ id: 'dns', name: 'DNS filter', state: 'Running', port: 5353 }
];
let selected = $state(services[0]);
let open = $state(true);
</script>
<SidePanel bind:open title={selected.name} width="22rem" dockAt={720} class="min-h-screen">
{#snippet header()}
<Badge variant={selected.state === 'Running' ? 'success' : 'secondary'}>{selected.state}</Badge>
{/snippet}
{#snippet panel()}
<dl class="grid grid-cols-[auto_1fr] gap-x-6 gap-y-3">
<dt class="text-muted-foreground">Port</dt>
<dd class="tabular-nums">{selected.port}</dd>
<dt class="text-muted-foreground">Restart</dt>
<dd>Unless stopped</dd>
</dl>
<div class="mt-6 flex gap-2">
<Button size="sm" variant="outline">Logs</Button>
<Button size="sm">Restart</Button>
</div>
{/snippet}
<div class="p-6">
<Table caption="Services" captionHidden>
<thead>
<tr><th>Service</th><th>State</th></tr>
</thead>
<tbody>
{#each services as s (s.id)}
<tr class={s.id === selected.id ? 'bg-muted' : ''}>
<td>
<button type="button" class="font-medium hover:underline" aria-current={s.id === selected.id || undefined} onclick={() => ((selected = s), (open = true))}>{s.name}</button>
</td>
<td class="text-muted-foreground">{s.state}</td>
</tr>
{/each}
</tbody>
</Table>
</div>
</SidePanel>
Notes
Notes
- Reach for it over a Sheet when the panel goes with a list. A Sheet covers
the page and has to be closed before the next row can be clicked; a docked
SidePanel leaves the list live, so the detail swaps as the reader moves down
it. Set
open = trueand change whatpanelrenders — it neither closes nor re-animates. dockAtis measured on the component, not the window. An app shell with its own navigation column docks only where the content really has the room. Pick awidthwell underdockAt, so the content keeps a usable column.- Docked, the panel is sticky at
top-0with its own scroll. Under a sticky app header, move it down withclasses={{ panel: 'top-14 max-h-[calc(100dvh-3.5rem)]' }}; give the root a height (class="h-full") to scroll the two columns separately. - Focus. Docked, opening does not move focus (the reader is still in the
list); closing from inside gives focus back to what had it before. Sliding
over, it is a modal: focus goes in and comes back on close. Resizing across
dockAtwhile open carries focus that was in the panel to its new place. - The panel remounts when the mode flips, so state kept only in the DOM
inside it (an uncontrolled input) does not survive a resize across
dockAt. Bind it to the app's state if it must.
Overlays · Dialog · ResponsiveDialog · Sheet · Drawer · Tooltip · Popover
driftwood
Layout
Actions
Forms
- Field
- Input
- FileInput
- FileList
- Textarea
- CodeEditor
- Combobox
- RadioGroup
- ColorSwatches
- NumberInput
- InlineEdit
- Label
- Select
- MultiSelect
- DatePicker
- TagsInput
- Checkbox
- Switch
- Slider
Feedback
Charts
Overlays
Navigation
Generated from the source by pnpm wiki · repository · v0.34.0



