Drawer
Pull-out panels: sides, dimensions, actions, shapes, nesting and life cycle.
When to use
Drawer opens details or a subtask from the side, maintaining the context of the current page. It is suitable for viewing a record and editing a form. For a small action next to the control, use Popover; for a separate solution in the center - Modal.
Drawer CSS prefixes show global ConfigProvider.prefixCls and local prefixCls without resetting state. Panel, mask, placements and content follow prefixCls. Native dialog and backdrop retain their rules; Input and Button separately inherit a common prefix. The draft and open dialog are saved.
Opening, sides and contents
bind:open synchronizes opening with the application. title sets the title, children — the body, extra — the header actions, footer — the bottom actions. Complex content is sent to Svelte snippets.
| Problem | Setting | Example |
|---|---|---|
| Open details | bind:open |
Main panel |
| Select side and size | placement, size |
Geometry |
| Add form actions | extra, footer |
Panel Actions |
| Open subtask | separate Drawer |
Nested panels |
| Set up closing | mask, keyboard |
Background and Escape |
| Select save content | destroyOnHidden |
Life cycle |
In the size example, choose an edge and drag the panel border. resizable changes the width of a side panel or the height of a top or bottom panel. When the application supplies size, update it in onResize. To let the panel keep its own size, use defaultSize.
Closure, shape and focus
closable controls the standard cross, keyboard controls Escape, mask.closable controls background closing, mask.blur controls blur. onClose reports an event after changing the internal open. Keep the cancel action clear, especially if one of the closing methods is disabled.
By default the backdrop keeps focus inside the panel. With mask={false}, the page stays interactive. focusable.trap controls focus trapping independently, and focusable.focusTriggerAfterClose controls whether focus returns to the trigger.
By default, visited children are saved after closing. destroyOnHidden removes them; forceRender creates in advance. For data that needs to survive DOM removal, store state above Drawer. Application form checks the fields before saving and closes the panel after the result.
Container, theme and API boundaries
With getContainer={false}, the panel stays in its current DOM branch. In modal mode the browser displays it in the top layer.
Use classNames and styles to style the header, body and footer. Use drawerRender to wrap the whole section, including its header and actions.
In the nested example, the child pushes its parent by 96 pixels. push sets the distance. The select popup inherits the child panel’s layer. Escape closes the list first and then the panel.
In container example, an open dialog is transferred between two DOM nodes. The new getter with the old node retains the contents; changing a node recreates it and resets the local draft. Closing with a change of container cancels the removal of the old panel; the new one remains closed until the next opening.
Drawer uses design tokens from the current theme for its appearance.
Examples
Regular panel
Native dialog, closing and draft.
<script lang="ts">
import { Button, Drawer, Input } from '@woodger/antd';
let open = $state(false);
let note = $state<string | undefined>(("Draft"));
</script>
<style>
.content {
display: grid;
gap: 20px;
}
p { margin: 0; }
</style>
<Button onclick={() => { open = true; }}>{("Open normal panel")}</Button>
<Drawer title={("Regular panel")} bind:open>
<div class="content"><p>{("Escape, cross and clicking on the background closes the panel.")}</p>
<Input aria-label={("Panel draft")} bind:value={note} /></div>
</Drawer>
Sides and dimensions
Four sides and preset/numeric/percentage sizes.
<script lang="ts">
import { Button, Drawer, RadioGroup, type DrawerPlacement, type DrawerSize } from '@woodger/antd';
let open = $state(false);
let placement = $state<DrawerPlacement>('right');
let size = $state<DrawerSize>('default');
</script>
<style>
.settings {
display: grid;
gap: 20px;
}
</style>
<div class="settings">
<RadioGroup aria-label={("Side Drawer")} bind:value={placement} options={(['top', 'right', 'bottom', 'left'])} />
<RadioGroup aria-label={("Size Drawer")} bind:value={size}
options={([{ label: 'Default', value: 'default' }, {
label: 'Large',
value: 'large'
}, { label: '256px', value: 256 }, { label: '50%', value: '50%' }])} />
<Button
onclick={() => { open = true; }}
>{("Open with selected sizes")}</Button>
</div>
<Drawer
title={("Size and side")}
bind:open
{placement}
{size}
maxSize={800}
resizable={{ onResize: next => { size = next; } }}
>
<p>
{("For top/bottom the size specifies the height, for left/right it specifies the width.")}
</p>
</Drawer>
extra and footer
Actions in the header and below the content.
<script lang="ts">
import { Button, Checkbox, Drawer } from '@woodger/antd';
let open = $state(false);
let loading = $state(false);
let applied = $state(0);
function apply() {
applied++;
open = false;
}
</script>
<style>
output {
display: block;
margin-block-start: 12px;
}
</style>
<Button onclick={() => { open = true; }}>{("Open action panel")}</Button>
<Drawer
title={("Panel actions")}
bind:open
{loading}
closable={{ placement: 'end' }}
styles={{ footer: `
display: flex;
justify-content: flex-end;
gap: var(--ant-margin-xs);
` }}
>
{#snippet extra()}
<Checkbox bind:checked={loading}>{("Show loading")}</Checkbox>
{/snippet}
<p>{("Extra is in the header, footer is after the scrollable content.")}</p>
{#snippet footer()}
<Button onclick={() => { open = false; }}>{("Cancel")}</Button>
<Button type="primary" disabled={loading} onclick={apply}>
{("Apply in Drawer")}
</Button>
{/snippet}
</Drawer>
<output aria-label={("Applications Drawer")}>
{("Applied: ")}{applied}
</output>
GetContainer=false leaves the dialog in this DOM branch. The modal panel still opens in the top layer of the browser.
Changing the target container recreates the content and resets the local draft.
DOM branch and container change
getContainer=false saves the DOM branch. Changing the target container recreates the content; dialog remains modal.
<script lang="ts">
import { Button, Input, Drawer } from '@woodger/antd';
let open = $state(false);
let transferredOpen = $state(false);
let alternate = $state(false);
let first = $state<HTMLDivElement>();
let second = $state<HTMLDivElement>();
let getContainer = $derived(() => (alternate ? second : first) ?? document.body);
</script>
<style>
.container {
display: grid;
gap: 16px;
padding: 20px;
border: 1px dashed var(--ant-color-border);
border-radius: 8px;
}
p { margin: 0; }
</style>
<div class="container" data-drawer-inline-example>
<p>
{("GetContainer=false leaves the dialog in this DOM branch. The modal panel still opens in the top layer of the browser.")}
</p>
<Button onclick={() => { open = true; }}>{("Open without DOM transfer")}</Button>
<Drawer title={("Panel in the current DOM")} bind:open getContainer={false}>
<p>
{("This is a native modal dialog; its visible area is not limited to the card.")}
</p>
</Drawer>
</div>
<div data-drawer-transfer-example>
<p>{("Changing the target container recreates the content and resets the local draft.")}</p>
<Button
onclick={() => { transferredOpen = true; }}
>{("Open Drawer with transfer")}</Button>
<div data-container="first" bind:this={first}></div>
<div data-container="second" bind:this={second}></div>
<Drawer
title={("Transfer Drawer")}
bind:open={transferredOpen}
{getContainer}
prefixCls="example-drawer"
destroyOnHidden
>
<p>{("Container: ")}{(alternate ? "second" : "first")}</p>
<Input aria-label={("Transfer draft")} defaultValue="Начальный текст" />
<Button
onclick={() => { alternate = !alternate; }}
>{("Change container")}</Button>
<Button onclick={() => { transferredOpen = false; alternate = !alternate; }}>
{("Close and change container")}
</Button>
</Drawer>
</div>
Nested panels
Opening the child pushes its parent aside. Choose a priority inside the child panel.
<script lang="ts">
import { Button, Drawer, Select } from '@woodger/antd';
let open = $state(false);
let child = $state(false);
</script>
<Button onclick={() => { open = true; }}>{("Open parent panel")}</Button>
<Drawer
title={("Parent panel")}
bind:open
size={480}
push={{ distance: 96 }}
zIndex={1400}
>
<Button onclick={() => { child = true; }}>{("Open subtask")}</Button>
<Drawer title={("Subtask")} bind:open={child} size={320}>
<Select
aria-label={("Priority")}
defaultValue="normal"
options={[
{ value: 'normal', label: ("Regular") },
{ value: 'high', label: ("High") }
]}
/>
</Drawer>
</Drawer>
Mask and Escape
blur, background closing and keyboard.
<script lang="ts">
import { Button, Checkbox, Drawer, Flex } from '@woodger/antd';
let open = $state(false);
let enabled = $state(true);
let closable = $state(false);
let blur = $state(true);
let keyboard = $state(true);
</script>
<Flex align="center" gap="medium" wrap>
<Checkbox bind:checked={enabled}>{("Show backdrop")}</Checkbox>
<Checkbox bind:checked={closable} disabled={!enabled}>
{("Close by background")}
</Checkbox>
<Checkbox bind:checked={blur} disabled={!enabled}>{("Blur background")}</Checkbox>
<Checkbox bind:checked={keyboard}>{("Close by Escape")}</Checkbox>
<Button onclick={() => { open = true; }}>{("Open with background settings")}</Button>
</Flex>
<Drawer
title={("Background settings")}
bind:open
{keyboard}
mask={{ enabled, blur, closable }}
>
<p>{("The cross remains available regardless of these settings.")}</p>
</Drawer>
Saving and deleting content
Local state of the child component.
Lifecycle.svelte<script lang="ts"> import { Button, Checkbox, Drawer } from '@woodger/antd'; import LocalCounter from './LocalCounter.svelte'; let open = $state(false); let destroyOnHidden = $state(false); </script> <style> .settings { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; } </style> <div class="settings"> <Checkbox bind:checked={destroyOnHidden}> {("Delete Drawer contents")} </Checkbox> <Button onclick={() => { open = true; }} >{("Check life cycle")}</Button> </div> <Drawer title={("Drawer Life Cycle")} bind:open {destroyOnHidden} ><LocalCounter /></Drawer>LocalCounter.svelte<script lang="ts"> import { Button } from '@woodger/antd'; let count = $state(0); </script> <Button onclick={() => { count++; }}>{("Change local state")}</Button> <output aria-label={("Local state Drawer")} >{("Changes: ")}{count}</output>
Component theme Drawer
Indents footer and layer; changing the theme saves the draft and RTL.
<script lang="ts">
import { Button, Checkbox, ConfigProvider, Drawer, Input } from '@woodger/antd';
let open = $state(false);
let enabled = $state(true);
let draft = $state(("Draft Drawer"));
const tokens = { footerPaddingBlock: 24, footerPaddingInline: 32, zIndexPopup: 1400 };
</script>
<style>
.settings {
display: grid;
gap: 24px;
}
label {
display: grid;
gap: 8px;
}
</style>
{#snippet footer()}
<Button onclick={() => { open = false; }}>{("Close topic review")}</Button>
{/snippet}
<ConfigProvider direction="rtl" theme={{
token: { colorBgElevated: '#fffbe6' }, components: {
Drawer: enabled ? tokens : {}
}
}}>
<Button onclick={() => { open = true; }}>{("Check thread Drawer")}</Button>
<Drawer title={("Drawer Theme")} bind:open {footer}>
<div class="settings">
<Checkbox bind:checked={enabled}>{("Apply Drawer tokens")}</Checkbox>
<label>{("Draft\n ")}<Input bind:value={draft} aria-label={("Draft theme Drawer")} />
</label>
<p>{("Switching tokens changes the footer and layer padding, preserving the entered text and RTL.")}</p>
</div>
</Drawer>
</ConfigProvider>
Member | Role | Card |
|---|---|---|
| Анна | Developer | |
| Михаил | Designer |
Form and view record
Member editing, validation, saving and tabs.
DrawerExample.svelte<script lang="ts"> import { untrack } from 'svelte'; import { Button, Checkbox, Drawer, Table, type DrawerPlacement, type DrawerSize, type TableColumn } from '@woodger/antd'; import DrawerEditor from './DrawerEditor.svelte'; interface Member { key: number; name: string; role: string; note: string; news: boolean; } let members = $state<Member[]>( [ { key: 1, name: "Anna", role: 'developer', note: "Maintains a component library", news: true }, { key: 2, name: "Mikhail", role: 'designer', note: "Responsible for design", news: false } ] ); let selected = $state<Member>(untrack(() => members[0])); let open = $state(false); let placement = $state<DrawerPlacement>('right'); let size = $state<DrawerSize>('default'); let destroyOnHidden = $state(false); let result = $state( ("Open your membership card. When you close, the unsaved draft will remain in the panel.") ); const columns: TableColumn<Member>[] = [ { key: 'name', title: "Member", dataIndex: 'name' }, { key: 'role', title: "Role", render: roleCell }, { key: 'action', title: "Card", render: actions } ]; let formId = $derived(`drawer-member-form-${selected.key}`); function save(values: Omit<Member, 'key'>) { members = members.map( (member) => member.key === selected.key ? { key: member.key, ...values } : member ); result = ("Member saved: " + String((values.name)) + "."); open = false; } </script> <style> .settings { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 24px; } .settings label { display: flex; align-items: center; gap: 8px; } select { padding: 4px 8px; color: var(--ant-color-text); background: var(--ant-color-bg-container); border: 1px solid var(--ant-color-border); border-radius: 6px; font: inherit; } .footer { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; } output { display: block; margin-top: 20px; color: var(--ant-color-text-secondary); } .record { color: var(--ant-color-text-secondary); font-size: 12px; } </style> {#snippet roleCell(member: Member)}{(({ developer: "Developer", designer: "Designer", manager: "Manager" } as Record<string, string>)[member.role])}{/snippet} {#snippet actions(member: Member)}<Button size="small" aria-label={("Edit: " + String((member.name)) + "")} onclick={() => { selected = member; open = true; }} >{("Edit")}</Button>{/snippet} {#snippet extra()}<span class="record">№{(selected.key)}</span>{/snippet} {#snippet footer()} <div class="footer"><Button onclick={() => { open = false; }}> {("Close card")} </Button><Button type="primary" htmlType="submit" form={formId} >{("Save member")}</Button></div> {/snippet} <div class="settings"> <label>{("Panel side ")}<select bind:value={placement} ><option value="right" >{("Right")}</option><option value="left" >{("Left")}</option><option value="top" >{("Top")}</option><option value="bottom" >{("Bottom")}</option></select></label> <label>{("Panel size ")}<select bind:value={size} ><option value="default" >{("Regular")}</option><option value="large" >{("Large")}</option><option value="50%" >{("Half screen")}</option></select></label> <Checkbox bind:checked={destroyOnHidden} >{("Reset card when closing")}</Checkbox> </div> <Table dataSource={(members)} columns={(columns)} caption={("Participants with retractable card")} pagination={(false)} scroll={{ x: 460 }} /> <output aria-label={("Participant card result")}>{result}</output> <Drawer bind:open title={("Member: " + String((selected.name)) + "")} {placement} {size} {destroyOnHidden} extra={(extra)} {footer} > {#key selected.key}<DrawerEditor name={selected.name} role={selected.role} note={selected.note} news={selected.news} {formId} onSave={save} />{/key} </Drawer>DrawerEditor.svelte<script lang="ts"> import { untrack } from 'svelte'; import { Checkbox, Collapse, Form, FormItem, Input, Select, Tabs, createForm, type SelectOption } from '@woodger/antd'; let { name, role, note, news, formId, onSave }: { name: string; role: string; note: string; news: boolean; formId: string; onSave: (values: { name: string; role: string; note: string; news: boolean }) => void } = $props(); const roles: SelectOption<string>[] = [ { value: 'developer', label: "Developer" }, { value: 'designer', label: "Designer" }, { value: 'manager', label: "Manager" } ]; const form = createForm<{ name: string; role: string; note: string; news: boolean }>({ initialValues: untrack(() => ({ name, role, note, news })), rules: ({ name: [{ required: true, message: "Enter the participant's name." }] }) }); </script> {#snippet preferences()} <Checkbox checked={form.values.news} onCheckedChange={(value) => form.setFieldValue('news', value)} >{("News for the participant")}</Checkbox> {/snippet} {#snippet notes()} <Collapse aria-label={("Notes cards")} defaultActiveKey="note" items={([{ key: 'note', label: "Comment about the participant", children: noteField }])} /> {/snippet} {#snippet noteField()} <FormItem name="note" label={("Note on card")}><Input value={form.values.note} onValueChange={(value) => form.setFieldValue('note', value)} /></FormItem> {/snippet} <Form {form} id={formId} onFinish={onSave}> <FormItem name="name" label={("Name on card")}><Input value={form.values.name} onValueChange={(value) => form.setFieldValue('name', value)} /></FormItem> <FormItem name="role" label={("Role on the card")}><Select value={form.values.role} onValueChange={(value) => form.setFieldValue('role', value ?? 'developer')} options={(roles)} /></FormItem> <Tabs aria-label={("Participant card sections")} items={([ { key: 'preferences', label: "Card notifications", children: preferences }, { key: 'notes', label: "Notes cards", children: notes } ])} /> </Form>
Panel, mask, placements and content follow prefixCls. Native dialog and backdrop retain their rules; Input and Button separately inherit a common prefix. The draft and open dialog are saved.
CSS prefixes Drawer
Common namespace ConfigProvider and local prefixCls; the state of the component is preserved when the name is changed.
<script lang="ts">
import { Checkbox, ConfigProvider, Drawer, Input, Button } from '@woodger/antd';
let custom = $state(true);
let local = $state(true);
const prefix = $derived(custom ? 'suite' : 'ant');
const localPrefix = $derived(local ? 'project-drawer' : '');
let open = $state(false);
let draft = $state(("Panel draft"));
</script>
<style>
.example,
.prefix-stage {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 16px;
min-width: 0;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
p { margin: 0; }
output { overflow-wrap: anywhere; }
</style>
<div class="example">
<div class="controls">
<Checkbox bind:checked={custom}>{("General prefix Drawer suite")}</Checkbox>
<Checkbox bind:checked={local}>{("Local prefix Drawer")}</Checkbox>
</div>
<ConfigProvider prefixCls={prefix} theme={{ cssVar: { prefix: 'drawer-theme' } }}>
<div class="prefix-stage">
<Button onclick={() => open = true}>{("Open Drawer with prefix")}</Button>
<Drawer prefixCls={localPrefix} bind:open title={("Drawer with prefix")}>
<Input bind:value={draft} aria-label={("Draft Drawer with prefix")} />
</Drawer>
</div>
</ConfigProvider>
<output
aria-label={("CSS prefix Drawer")}
>{("General: ")}{prefix}{("; local: ")}{(localPrefix
|| ("from the provider"))}</output>
<p>
{("Panel, mask, placements and content follow prefixCls. Native dialog and backdrop retain their rules; Input and Button separately inherit a common prefix. The draft and open dialog are saved.")}
</p>
</div>
API
The reference lists Drawer properties and links to working examples.
| Theme | Example or limitation |
|---|---|
| Basic | Modal panel and focus. |
| Custom Placement | top, right, bottom and left. |
| Resizable | Drag the edge to change the width or height. |
| Loading | Shows a Skeleton in the body while loading. |
| Extra Actions | extra and footer via Snippet. |
| Render in current dom | DOM remains in place; The native top layer is not limited to the card. |
| Submit form in drawer | Validation and submit from footer. |
| Preview drawer | View and edit table member. |
| Multi-level drawer | The child panel pushes its parent by the configured distance. |
| Preset size | default 378px, large 736px and custom size. |
| mask | Controls the backdrop, its blur and whether clicking it closes the panel. |
| Closable placement | Places the close button at the end of the header. |
| Custom semantic dom styling | Use classNames and styles to customize individual parts of the panel. |
Drawer
| Property | Description | Type | Default |
|---|---|---|---|
closeIcon | The close icon. With closable omitted, null hides the close button. | DrawerCloseIcon | — |
defaultSize | Initial size when size is omitted. | DrawerSize | 378 |
resizable | Drag the edge to change the width or height. | boolean | DrawerResizableConfig | false |
maxSize | Maximum size in pixels while dragging. | number | — |
push | Offsets the parent panel when a child opens. | boolean | DrawerPushConfig | { distance: 180 } |
loading | Shows a Skeleton in the body while loading. | boolean | false |
drawerRender | Receives the panel section so it can be wrapped or replaced. | Snippet<[section: Snippet]> | — |
panelRef | Use bind:panelRef to access the section element. | HTMLDivElement | — |
focusable | Traps focus and optionally restores it to the trigger after closing. | DrawerFocusableConfig | — |
autoFocus | Moves focus into the panel on open. | boolean | true |
classNames | Classes for individual panel elements. | DrawerSemantic | — |
styles | Styles for individual panel elements. | DrawerSemantic | — |
rootStyle | Additional styles on the root dialog. | string | — |
motion | Configures the transition for the selected edge. | DrawerMotionConfig | (placement) => DrawerMotionConfig | — |
maskMotion | Configures the backdrop transition. | DrawerMotionConfig | — |
zIndex | Sets the panel layer used by nested popups. | number | — |
afterOpenChange | Reports opening or closing when the transition completes. | (open: boolean) => void | — |
prefixCls | Full CSS prefix of the component and its parts. A non-empty local prop takes precedence; empty string and undefined inherit ConfigProvider. The namespace of the topic is set separately. | string | ConfigProvider.prefixCls + "-drawer" |
open | Supports bind:open. | boolean | false |
title | Title and available name of the panel. | DrawerContent | — |
children | Main content. | Snippet | — |
extra | Additional actions in the header. | DrawerContent | — |
footer | Actions below scrollable content. | DrawerContent | — |
placement | Physical side of the screen. | top | right | bottom | left | right |
size | Width or height by placement; default 378px, large 736px. | default | large | number | string | default |
closable | Configures the close button, its icon and accessible name. | DrawerClosable | true |
keyboard | Closing by Escape. | boolean | true |
mask | Controls the backdrop, its blur and whether clicking it closes the panel. | DrawerMask | closable=true, blur=false |
forceRender | Mounts the content before the first opening. | boolean | false |
destroyOnHidden | Removes children after closing; the local state is reset. | boolean | false |
getContainer | Container, getter, selector or false. | GetContainer | body / ConfigProvider |
onClose | User close request event. | (event: Event) => void | — |
class | Root native dialog class. | string | — |
style | CSS root native dialog; the contract is different from React panel style. | string | — |
Use bind:panelRef to access the open panel section.
Semantic DOM
Use classNames and styles to style the header, body, footer and resize handle.
| Element | Purpose |
|---|---|
dialog.ant-svelte-drawer | The root dialog receives class and style. |
.ant-drawer-mask | Mask with pointer down/up and blur processing. |
.ant-drawer-content-wrapper | Panel geometry by placement and size. |
.ant-drawer-section | Header, body and footer area. |
.ant-drawer-header | Heading, standard cross and extra. |
.ant-drawer-body | Scrollable content. |
.ant-drawer-footer | Actions under the content. |
Registration tokens
The draggerSize token sets the handle thickness when resizable is enabled.
| Token | Purpose |
|---|---|
zIndexPopup | CSS layer of the root dialog; native top layer is preserved. |
footerPaddingBlock | Vertical footer padding. |
footerPaddingInline | Horizontal footer padding. |
draggerSize | Thickness of the draggable resize area. |
| Token | Meaning |
|---|---|
colorBgElevated | #ffffff |
colorBgMask | rgba(0,0,0,0.45) |
colorTextHeading | rgba(0,0,0,0.88) |
colorText | rgba(0,0,0,0.88) |
fontSizeLG | 16 |
paddingLG | 24 |
FAQ
Are fields saved after closing?
By default, the visited body remains mounted. destroyOnHidden removes it and the local state.
Is it possible to limit the Drawer to a card via getContainer:false?
No. The DOM remains in place, but the native modal dialog is in the top layer of the viewport.
How can I keep the actions visible while loading?
Enable loading in the actions example. A skeleton replaces the body while the header and footer stay in place.
Do Drawer tokens work?
draggerSize controls the resize handle area. footerPaddingBlock and footerPaddingInline set the footer padding.
How to submit a form from the footer?
Link the button to the form via form/id and htmlType:submit.
Do you need your own focus trap?
By default Drawer traps focus when the backdrop is enabled and restores it on close. If the trigger is removed, choose another element to receive focus.