Drawer
A Drawer is a panel that slides in from the edge of the screen over the page. It holds a form, the details of an item or a set of actions: a task that is too heavy for a popover and that the user should do without leaving the page. It is drawn above the page and, with a mask, keeps the page behind it out of reach.
When to use
- Use it to create or edit a set of information with a form, to show the details of a row or a card, or for a subtask that is too heavy for a popover and belongs to the task on the page.
- A dialog that asks for an answer in the middle of the screen is a Modal. A short notice that needs no answer is a Message. A panel that sits beside the page and lets it work is a Drawer with
mask: false. - A Drawer inside another Drawer is nested: the parent moves aside while the child is open. Do not stack more than two levels.
Examples
<script lang="ts">
import { Button, Drawer } from 'svelte-ant-design';
let open = $state(false);
let log = $state('');
// Every opening starts with an empty log, so that the last way to close is the only thing it says.
function show() {
log = '';
open = true;
}
</script>
<!-- bind:open: the close button, the mask and Escape close it by themselves; onclose hears each of them first. -->
<div class="stack">
<Button type="primary" onclick={show}>Open Drawer</Button>
<Drawer
bind:open
title="Basic Drawer"
onclose={() => (log = 'asked to close')}
onafteropenchange={(opened) => {
if (!opened) log = `${log}, then gone`;
}}
>
<p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p>
</Drawer>
<output class="caption">{log}</output>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
<script lang="ts">
import { Button, Drawer, type DrawerPlacement } from 'svelte-ant-design';
const sides: DrawerPlacement[] = ['top', 'right', 'bottom', 'left'];
let open = $state(false);
let placement = $state<DrawerPlacement>('right');
function show(side: DrawerPlacement) {
placement = side;
open = true;
}
</script>
<!-- placement: the side the panel comes from. The sides are physical (left stays on the left in right-to-left); a top or a bottom panel is sized by its height. -->
<div class="stack">
<div class="row">
{#each sides as side (side)}
<Button onclick={() => show(side)}>{side}</Button>
{/each}
</div>
<Drawer bind:open {placement} title="Placement: {placement}">
<p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p>
</Drawer>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
</style>
<script lang="ts">
import { Button, Drawer, type DrawerSize } from 'svelte-ant-design';
const sizes: { label: string; size: DrawerSize }[] = [
{ label: 'default (378 px)', size: 'default' },
{ label: 'large (736 px)', size: 'large' },
{ label: '500', size: 500 },
{ label: "'50%'", size: '50%' },
{ label: "'20vw'", size: '20vw' }
];
let open = $state(false);
let chosen = $state<DrawerSize>('default');
let label = $state('');
function show(entry: (typeof sizes)[number]) {
chosen = entry.size;
label = entry.label;
open = true;
}
</script>
<!-- size: the width of a left or right panel and the height of a top or bottom one. A number is px, a string is any CSS length; the panel is never larger than the page. -->
<div class="stack">
<div class="row">
{#each sizes as entry (entry.label)}
<Button onclick={() => show(entry)}>{entry.label}</Button>
{/each}
</div>
<Drawer bind:open size={chosen} title="size: {label}">
<p>Some contents...</p>
<p>Some contents...</p>
</Drawer>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
</style>
<script lang="ts">
import { Button, Drawer } from 'svelte-ant-design';
type Variant = 'extra' | 'end' | 'disabled' | 'none' | 'icon';
const variants: { id: Variant; label: string }[] = [
{ id: 'extra', label: 'extra' },
{ id: 'end', label: "closable.placement: 'end'" },
{ id: 'disabled', label: 'closable.disabled' },
{ id: 'none', label: 'closable: false' },
{ id: 'icon', label: 'closeIcon' }
];
let open = $state(false);
let variant = $state<Variant>('extra');
let log = $state('');
const closable = $derived(variant === 'end' ? { placement: 'end' as const } : variant === 'disabled' ? { disabled: true } : variant === 'none' ? false : true);
function show(id: Variant) {
variant = id;
log = '';
open = true;
}
</script>
{#snippet actions()}
<div class="row">
<Button
size="small"
onclick={() => {
log = 'Cancel pressed';
open = false;
}}>Cancel</Button
>
<Button
size="small"
type="primary"
onclick={() => {
log = 'OK pressed';
open = false;
}}>OK</Button
>
</div>
{/snippet}
{#snippet heart()}
<span aria-hidden="true">♥</span>
{/snippet}
<!-- The header has the close button (at the start by default), the title, and the extra actions at the end. -->
<div class="stack">
<div class="row">
{#each variants as entry (entry.id)}
<Button onclick={() => show(entry.id)}>{entry.label}</Button>
{/each}
</div>
<Drawer
bind:open
title="Drawer with a header"
extra={variant === 'extra' ? actions : undefined}
{closable}
closeIcon={variant === 'icon' ? heart : undefined}
>
<p>Some contents...</p>
<p>{variant === 'disabled' ? 'The close button is shown but does nothing; the mask and Escape still close it.' : 'Some contents...'}</p>
</Drawer>
<output class="caption">{log}</output>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
<script lang="ts">
import { Button, Drawer, Form, FormItem, Input, createForm } from 'svelte-ant-design';
interface Account {
name: string;
email: string;
}
const form = createForm<Account>();
let open = $state(false);
let result = $state('');
// The footer is outside the <Form> in the page, so it asks the form to validate and reads the values from it.
async function save() {
try {
const values = await form.validateFields();
result = `Saved: ${JSON.stringify(values)}`;
open = false;
} catch {
result = '';
}
}
</script>
{#snippet actions()}
<div class="actions">
<Button onclick={() => (open = false)}>Cancel</Button>
<Button type="primary" onclick={save}>Submit</Button>
</div>
{/snippet}
<!-- A form in a Drawer: the task stays in the context of the page. Validation keeps the Drawer open while a field is wrong. -->
<div class="stack">
<Button type="primary" onclick={() => (open = true)}>New account</Button>
<Drawer bind:open title="Create a new account" size="large" footer={actions}>
<Form {form} layout="vertical" initialValues={{ name: '', email: '' }}>
<FormItem name="name" label="Name" rules={[{ required: true, message: 'Please enter a name' }]}>
{#snippet children(field)}
<Input bind:value={field.value} status={field.status} placeholder="Please enter a name" {...field.attrs} />
{/snippet}
</FormItem>
<FormItem name="email" label="Email" rules={[{ required: true, message: 'Please enter an email' }]}>
{#snippet children(field)}
<Input bind:value={field.value} status={field.status} placeholder="Please enter an email" {...field.attrs} />
{/snippet}
</FormItem>
</Form>
</Drawer>
{#if result}<output class="caption">{result}</output>{/if}
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.actions {
display: flex;
justify-content: flex-end;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
a control of the page
<script lang="ts">
import { Button, Drawer } from 'svelte-ant-design';
type Kind = 'dimmed' | 'fixed' | 'none' | 'keys';
const kinds: { id: Kind; label: string }[] = [
{ id: 'dimmed', label: 'Dimmed mask' },
{ id: 'fixed', label: 'mask.closable: false' },
{ id: 'none', label: 'No mask' },
{ id: 'keys', label: 'keyboard: false' }
];
let open = $state(false);
let kind = $state<Kind>('dimmed');
let clicks = $state(0);
const mask = $derived(kind === 'fixed' ? { closable: false } : kind === 'none' ? false : true);
function show(id: Kind) {
kind = id;
open = true;
}
</script>
<!-- A mask dims the page and makes the Drawer modal (the page is locked and out of reach). With no mask it is a panel beside the page: the page works, scrolls, and Escape closes it only while focus is inside. -->
<div class="stack">
<div class="row">
{#each kinds as entry (entry.id)}
<Button onclick={() => show(entry.id)}>{entry.label}</Button>
{/each}
</div>
<div class="field">
<span class="caption">a control of the page</span>
<Button onclick={() => clicks++}>Count a click</Button>
<output class="caption">clicks: {clicks}</output>
</div>
<Drawer bind:open title="Drawer: {kinds.find((entry) => entry.id === kind)?.label}" {mask} keyboard={kind !== 'keys'}>
<p>{kind === 'none' ? 'The page behind is not dimmed: press "Count a click" while this panel is open.' : 'Press the mask, or Escape.'}</p>
<p>{kind === 'fixed' ? 'The mask does not close it; the close button and Escape do.' : ''}</p>
<p>{kind === 'keys' ? 'Escape does nothing here; the mask and the close button close it.' : ''}</p>
</Drawer>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
push of the parent
<script lang="ts">
import { Button, Drawer, type DrawerPlacement } from 'svelte-ant-design';
let open = $state(false);
let inner = $state(false);
let side = $state<DrawerPlacement>('right');
let pushed = $state<'default' | 'off' | 'near'>('default');
const push = $derived(pushed === 'off' ? false : pushed === 'near' ? { distance: 60 } : true);
const labels = { default: 'push: true (180 px)', off: 'push: false', near: 'push: { distance: 60 }' };
function show(next: DrawerPlacement) {
side = next;
inner = true;
}
</script>
<!-- A Drawer written inside another one is nested: while it is open the parent moves aside by its own push distance (only for a child of the same side). Only the lowest layer dims the page: the child keeps a clear mask that still takes the press outside it. -->
<div class="stack">
<div class="field">
<span class="caption">push of the parent</span>
<div class="row">
{#each Object.entries(labels) as [id, label] (id)}
<Button type={pushed === id ? 'primary' : 'default'} onclick={() => (pushed = id as typeof pushed)}>{label}</Button>
{/each}
</div>
</div>
<Button type="primary" onclick={() => (open = true)}>Open drawer</Button>
<Drawer bind:open title="Parent Drawer" size={520} {push}>
<div class="stack">
<div class="row">
<Button type="primary" onclick={() => show('right')}>Two-level drawer</Button>
<Button onclick={() => show('left')}>From the other side</Button>
</div>
<p>The child comes from the {side}. The parent moves only when it is of the same side.</p>
</div>
<Drawer bind:open={inner} title="Child Drawer" size={320} placement={side}>
<p>This is the second level.</p>
</Drawer>
</Drawer>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
container={false}
Render in current DOM
a control of the page, outside the region
<script lang="ts">
import { Button, Drawer } from 'svelte-ant-design';
let open = $state(false);
let clicks = $state(0);
</script>
<!-- container={false} leaves the Drawer where it is written: it covers its nearest positioned parent only and is a panel of that region, not a modal. The rest of the page works. -->
<div class="stack">
<div class="field">
<span class="caption">container={'{false}'}</span>
<div class="region">
<Button type="primary" onclick={() => (open = true)}>Open in this region</Button>
<p>Render in current DOM</p>
<Drawer bind:open container={false} title="Basic Drawer" size={240}>
<p>Its layer covers the region only.</p>
</Drawer>
</div>
</div>
<div class="field">
<span class="caption">a control of the page, outside the region</span>
<Button onclick={() => clicks++}>Count a click</Button>
<output class="caption">clicks while the panel is open: {clicks}</output>
</div>
</div>
<style>
.stack {
display: grid;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.region {
position: relative;
box-sizing: border-box;
justify-self: stretch;
min-height: 260px;
padding: 16px;
border: 1px dashed var(--ads-color-border);
border-radius: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
default: the content stays after a close
destroyOnHidden
forceRender
<script lang="ts">
import { onMount } from 'svelte';
import { Button, Drawer } from 'svelte-ant-design';
let kept = $state(false);
let destroyed = $state(false);
let forced = $state(false);
let present = $state('');
// forceRender: the content is in the page, hidden, before the first opening.
onMount(() => {
present = document.querySelector('[data-forced-content]') ? 'yes' : 'no';
});
</script>
<!-- destroyOnHidden removes the content on every close (what was typed is gone); forceRender puts it in the page before the first opening. -->
<div class="stack">
<div class="field">
<span class="caption">default: the content stays after a close</span>
<Button onclick={() => (kept = true)}>Keep the content</Button>
</div>
<div class="field">
<span class="caption">destroyOnHidden</span>
<Button onclick={() => (destroyed = true)}>Remove the content</Button>
</div>
<div class="field">
<span class="caption">forceRender</span>
<Button onclick={() => (forced = true)}>Pre-rendered</Button>
<output class="caption">its content is in the page before the first opening: {present}</output>
</div>
<Drawer bind:open={kept} title="Keeps its content">
<input aria-label="Note" placeholder="Type, close, open again" />
</Drawer>
<Drawer bind:open={destroyed} destroyOnHidden title="Removes its content">
<input aria-label="Note" placeholder="Type, close, open again" />
</Drawer>
<Drawer bind:open={forced} forceRender title="Pre-rendered">
<p data-forced-content>This paragraph was in the page from the start.</p>
</Drawer>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
<script lang="ts">
import { Button, Drawer } from 'svelte-ant-design';
let open = $state(false);
</script>
<!-- class and style go on the panel, rootClassName and rootStyle on the layer; classNames and styles reach each part (root, mask, wrapper, section, header, title, close, extra, body, footer, dragger). zIndex sets the level of the layer. -->
<div class="stack">
<Button onclick={() => (open = true)}>Open a styled Drawer</Button>
<Drawer
bind:open
title="Custom semantic styling"
footer="Footer"
class="styled-panel"
style="border-radius: 12px 0 0 12px"
rootClassName="styled-root"
rootStyle="--demo-accent: #722ed1"
zIndex={1010}
classNames={{ title: 'styled-title', body: 'styled-body' }}
styles={{
header: { background: 'var(--demo-accent)' },
mask: { 'background-color': 'rgba(114, 46, 209, 0.25)' },
footer: { 'text-align': 'center' }
}}
>
<p>A class on the panel, a style on the layer, a class and a style on three parts.</p>
</Drawer>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
:global(.styled-title) {
color: #ffffff;
}
:global(.styled-body) {
font-style: italic;
}
</style>
<script lang="ts">
import type { Snippet } from 'svelte';
import { Button, Drawer } from 'svelte-ant-design';
let open = $state(false);
</script>
{#snippet frame(content: Snippet)}
<div class="frame">{@render content()}</div>
{/snippet}
<!-- drawerRender gets the content of the panel (header, body, footer) as a snippet and may wrap it. -->
<div class="stack">
<Button onclick={() => (open = true)}>Open Drawer</Button>
<Drawer bind:open title="Custom drawer content" footer="Footer" drawerRender={frame}>
<p>The whole content of the panel sits inside a framed box.</p>
</Drawer>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.frame {
display: flex;
flex: 1 1 auto;
flex-direction: column;
min-height: 0;
border-inline-start: 4px solid var(--ads-color-primary);
}
</style>
<script lang="ts">
import { Button, Drawer } from 'svelte-ant-design';
type Kind = 'default' | 'free' | 'stay';
let open = $state(false);
let kind = $state<Kind>('default');
const focusable = $derived(kind === 'free' ? { trap: false } : kind === 'stay' ? { focusTriggerAfterClose: false } : undefined);
function show(next: Kind) {
kind = next;
open = true;
}
</script>
<!-- By default focus goes to the panel, Tab stays inside and focus goes back to the button that opened it. focusable turns the trap or the return off. -->
<div class="stack">
<div class="row">
<Button onclick={() => show('default')}>Default</Button>
<Button onclick={() => show('free')}>trap: false</Button>
<Button onclick={() => show('stay')}>focusTriggerAfterClose: false</Button>
</div>
<Drawer bind:open title="focusable: {kind}" {focusable}>
<p>Press Tab: {kind === 'free' ? 'it leaves the Drawer for the page.' : 'it goes around inside.'}</p>
<input aria-label="A field" placeholder="A field" />
</Drawer>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
</style>
<script lang="ts">
import { Button, Drawer, Select, type SelectValue } from 'svelte-ant-design';
let open = $state(false);
let city = $state<SelectValue | undefined>('lisbon');
</script>
<!-- The list of a Select opens above the Drawer and takes typing, Escape closes the list first and the Drawer on the second press. -->
<div class="stack">
<Button onclick={() => (open = true)}>A Drawer with a Select</Button>
<Drawer bind:open title="Where to?">
<div class="field">
<span class="caption">City</span>
<Select aria-label="City" showSearch options={['lisbon', 'porto', 'faro']} bind:value={city} style="width: 200px" />
</div>
</Drawer>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
<script lang="ts">
import { Button, Drawer } from 'svelte-ant-design';
let open = $state(false);
const lines = Array.from({ length: 40 }, (_, index) => index + 1);
</script>
<!-- A long body scrolls on its own: the header and the footer stay in place, and the page behind does not scroll. -->
<div class="stack">
<Button onclick={() => (open = true)}>Open a long Drawer</Button>
<Drawer bind:open title="A long body" footer="The footer stays at the bottom">
{#each lines as line (line)}
<p>Line {line}</p>
{/each}
</Drawer>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
</style>
<script lang="ts">
import { Button, Drawer, type DrawerPlacement } from 'svelte-ant-design';
let open = $state(false);
let placement = $state<DrawerPlacement>('right');
let log = $state('');
function show(side: DrawerPlacement) {
placement = side;
log = '';
open = true;
}
</script>
<!-- resizable draws a strip on the inner edge. Drag it, or focus it and press the arrow keys (10 px, Shift 50 px), Home and End. minSize and maxSize (px) set the stops; the size stays after a close. -->
<div class="stack">
<div class="row">
<Button onclick={() => show('right')}>right</Button>
<Button onclick={() => show('bottom')}>bottom</Button>
</div>
<Drawer
bind:open
{placement}
title="Resizable Drawer"
size={320}
minSize={240}
maxSize={640}
resizable={{
onresizestart: () => (log = 'resizing...'),
onresize: (size) => (log = `size: ${size} px`),
onresizeend: () => (log = `${log} (done)`)
}}
>
<p>Drag the strip on the inner edge, or press the arrow keys when it has focus.</p>
<output class="caption">{log}</output>
</Drawer>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
API
Props of Drawer
| Property | Description | Type | Default |
|---|---|---|---|
| open | Whether the Drawer is shown. bind:open works: a way to close sets it to false. | boolean | false |
| title | The title; it names the panel. 0 is shown. With no title give the Drawer an aria-label. | string | number | Snippet | none |
| extra | The actions at the end of the header. A header with an extra alone is drawn. | string | number | Snippet | none |
| children | The body. It scrolls on its own. | Snippet | none |
| footer | The footer, at the bottom of the panel. None without it. | string | number | Snippet | none |
| placement | The side the panel comes from. The sides are physical. | 'top' | 'right' | 'bottom' | 'left' | 'right' |
| size | The width of a left or right panel, the height of a top or bottom one. default is 378 px, large 736 px; a number is px; a string is a CSS length. It replaces the deprecated width and height. | 'default' | 'large' | number | string | 'default' |
| closable | The close button. false removes it; disabled shows it and it does nothing; placement is logical and mirrors in right-to-left; aria-label is its name (default Close). | boolean | { closeIcon?: Snippet; disabled?: boolean; placement?: 'start' | 'end'; 'aria-label'?: string } | true |
| closeIcon | Replaces the cross. To hide the button use closable: false. | Snippet | a cross |
| mask | The dimmed backdrop. Only the lowest of the open layers (Drawers and Modals) dims the page; a layer above keeps a clear mask that still takes the press. closable (default true): a press on it asks to close. With no mask the Drawer is not modal: the page is not locked, not out of reach, Tab is not trapped, aria-modal is false. | boolean | { enabled?: boolean; closable?: boolean } | true |
| keyboard | Escape closes the Drawer. A modal Drawer takes Escape when it is the top layer; a non-modal one only while focus is inside it. | boolean | true |
| push | How this Drawer moves aside when a nested Drawer of the same side opens. false keeps it still; a number is px, a string a CSS length. | boolean | { distance?: string | number } | { distance: 180 } |
| zIndex | The z-index of the layer (token --ads-drawer-z-index): the level of the Modal, under the popup layers. | number | 1000 |
| container | Where the layer goes: an element, a function, a selector. false leaves the Drawer where it is written: it covers its nearest positioned parent only and is not modal. | HTMLElement | (() => HTMLElement) | string | false | document.body |
| destroyOnHidden | Remove the content on every close. | boolean | false |
| forceRender | Put the Drawer in the page, hidden, before the first opening. | boolean | false |
| focusable | Focus. trap: Tab and Shift+Tab stay inside (a modal Drawer). focusTriggerAfterClose: focus goes back to what had it before. On open focus goes to the panel itself. | { trap?: boolean; focusTriggerAfterClose?: boolean } | { trap: true, focusTriggerAfterClose: true } |
| resizable | A strip on the inner edge that the pointer or the arrow keys move (a focusable separator). The callbacks report the size in px; a key press is one gesture. The size stays after a close and goes when size or placement changes. | boolean | { onresizestart?: () => void; onresize?: (size: number) => void; onresizeend?: () => void; 'aria-label'?: string } | false |
| maxSize | The largest size, in px, while resizing. Never larger than the container. | number | the container |
| minSize | The smallest size, in px, while resizing. Ours: React has none, and its panel shrank to 7 px. | number | 100 |
| drawerRender | Gets the content of the panel (header, body, footer) as a snippet and may wrap it. | Snippet<[Snippet]> | none |
| class | A class on the panel (the section). | string | none |
| style | A style on the panel. | string | none |
| rootClassName | A class on the layer that holds the mask and the panel. | string | none |
| rootStyle | A style on the layer. | string | none |
| classNames | Classes for the parts: root, mask, wrapper, section, header, title, close, extra, body, footer, dragger. | { root?: string; mask?: string; wrapper?: string; section?: string; header?: string; title?: string; close?: string; extra?: string; body?: string; footer?: string; dragger?: string } | none |
| styles | Inline styles for the same parts. | { root?: SemanticStyle; mask?: SemanticStyle; wrapper?: SemanticStyle; section?: SemanticStyle; header?: SemanticStyle; title?: SemanticStyle; close?: SemanticStyle; extra?: SemanticStyle; body?: SemanticStyle; footer?: SemanticStyle; dragger?: SemanticStyle } | none |
| onclose | The close button, the mask or Escape asked to close. The Drawer closes after the call unless it calls event.preventDefault(). | (event: MouseEvent | KeyboardEvent) => void | none |
| onafteropenchange | After the enter animation (true) or the leave animation (false) ends; at once under prefers-reduced-motion. | (open: boolean) => void | none |
Differences from Ant Design: the close button, the mask and Escape close the Drawer unless
onclose calls event.preventDefault() (React leaves closing to you); focus goes to the panel, which carries the role and the name; a Drawer with no mask or rendered in place is not modal; resizable has a keyboard and a minimum (minSize); size replaces the deprecated width and height. Not yet: loading and mask.blur. Not taken: a service that opens a Drawer from code (only Angular has one).Design tokens
| Token | Description | Default |
|---|---|---|
| --ads-drawer-z-index | The level of the layer. | 1000 |
| --ads-drawer-mask-bg | The colour of the mask. | rgba(0, 0, 0, 0.45) |
| --ads-drawer-bg | The background of the panel. | #ffffff |
| --ads-drawer-size | The size default. | 378px |
| --ads-drawer-size-large | The size large. | 736px |
| --ads-drawer-shadow-right | The shadow of a right panel (cast to the left). | -6px 0 16px 0 rgba(0, 0, 0, 0.08), -3px 0 6px -4px rgba(0, 0, 0, 0.12), -9px 0 28px 8px rgba(0, 0, 0, 0.05) |
| --ads-drawer-shadow-left | The shadow of a left panel. | 6px 0 16px 0 rgba(0, 0, 0, 0.08), 3px 0 6px -4px rgba(0, 0, 0, 0.12), 9px 0 28px 8px rgba(0, 0, 0, 0.05) |
| --ads-drawer-shadow-top | The shadow of a top panel. | 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05) |
| --ads-drawer-shadow-bottom | The shadow of a bottom panel. | 0 -6px 16px 0 rgba(0, 0, 0, 0.08), 0 -3px 6px -4px rgba(0, 0, 0, 0.12), 0 -9px 28px 8px rgba(0, 0, 0, 0.05) |
| --ads-drawer-header-padding | The padding of the header. | 16px 24px |
| --ads-drawer-header-border | The line under the header. | rgba(5, 5, 5, 0.06) |
| --ads-drawer-title-color | The colour of the title. | rgba(0, 0, 0, 0.88) |
| --ads-drawer-title-font-size | The font size of the title. | 16px |
| --ads-drawer-title-line-height | The line height of the title. | 24px |
| --ads-drawer-title-font-weight | The weight of the title. | 600 |
| --ads-drawer-close-size | The size of the close button. | 24px |
| --ads-drawer-close-gap | The gap between the close button and the title. | 8px |
| --ads-drawer-close-color | The colour of the close button. | rgba(0, 0, 0, 0.45) |
| --ads-drawer-close-color-hover | The colour of the close button on the hover. | rgba(0, 0, 0, 0.88) |
| --ads-drawer-close-bg-hover | The fill of the close button on the hover. | rgba(0, 0, 0, 0.06) |
| --ads-drawer-body-color | The colour of the text. | rgba(0, 0, 0, 0.88) |
| --ads-drawer-body-padding | The padding of the body. | 24px |
| --ads-drawer-footer-padding | The padding of the footer. | 8px 16px |
| --ads-drawer-footer-border | The line above the footer. | rgba(5, 5, 5, 0.06) |
| --ads-drawer-motion-duration | The duration of the slide and of the fade of the mask. | 0.3s |
| --ads-drawer-motion-ease | The curve of the slide and of the fade. | ease |
| --ads-drawer-dragger-size | The width of the visible line of the resize strip. | 4px |
| --ads-drawer-dragger-hit | The width of the area that takes a press, half of it outside the panel. | 8px |
| --ads-drawer-dragger-hover-bg | The colour of the strip on the hover, the focus and the drag. | var(--ads-color-primary) |
Accessibility
- The panel is
role="dialog"and is named by its title (aria-labelledby). With no title give it anaria-label(a warning says so in development). A modal Drawer hasaria-modal="true"; one with no mask, or rendered in place, hasaria-modal="false". - Focus moves to the panel itself (not to the close button, so the title is announced first). In a modal Drawer Tab and Shift+Tab stay inside: Tab on the last element goes to the first. When the Drawer closes, focus goes back to the button that opened it.
- The page behind a modal Drawer is out of reach of the keyboard, the pointer and assistive technology (
inert;aria-hiddenwhere a browser does not knowinert). A Drawer with no mask, or rendered in place, leaves the page reachable and does not trap Tab. - Escape closes the Drawer that is on top; with a Select open inside it, Escape closes the list first. A Drawer with no mask takes Escape only while focus is inside it. A key that ends an IME composition does not close anything.
keyboard: falseturns Escape off. - A modal Drawer keeps the page from scrolling and from jumping sideways when its scrollbar goes away, up to the end of the leave animation. Not handled: iOS Safari before 16 scrolls a locked page under a finger.
- The resize strip is a focusable
separator(the window splitter pattern) with its value, its limits and a name (Resize); the arrow keys, Home and End move it. React's strip has no role and no keyboard, and shrinks the panel to a few pixels; hereminSizeis 100 px by default. - Contrast: the title and the text are about 15:1 on the panel, the close icon 3:1 (non-text contrast). The strip takes the primary colour on the hover and the focus. In forced colors the panel has a border on its inner edge, and the close button and the strip stay visible. The slide stops under
prefers-reduced-motion. - Known limit: a Drawer opened from inside a popup (for example from the list of a Select) is outside that popup, so a press in it closes the popup and takes the Drawer with it. Open it from the page, or give the popup's content a place of its own with
container. - Not checked: a real screen reader other than Orca (NVDA, JAWS, VoiceOver, a phone), a real touch device, and a real Safari. Checked: Orca with Firefox (the document starts inside a modal Drawer, Tab goes around inside, the strip is read as a splitter with its value), and the keys, focus and the page behind in Chromium, Firefox and WebKit, a touch drag in an emulated Chromium, and the lowest supported browser versions.