Ant Design Svelte

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.

Sides and dimensions

Four sides and preset/numeric/percentage sizes.

Applied: 0

extra and footer

Actions in the header and below the content.

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.

Nested panels

Opening the child pushes its parent aside. Choose a priority inside the child panel.

Mask and Escape

blur, background closing and keyboard.

Saving and deleting content

Local state of the child component.

Component theme Drawer

Indents footer and layer; changing the theme saves the draft and RTL.

Open your membership card. When you close, the unsaved draft will remain in the panel.

Form and view record

Member editing, validation, saving and tabs.

General: suite; local: project-drawer

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.

API

The reference lists Drawer properties and links to working examples.

Example themes
ThemeExample or limitation
BasicModal panel and focus.
Custom Placementtop, right, bottom and left.
ResizableDrag the edge to change the width or height.
LoadingShows a Skeleton in the body while loading.
Extra Actionsextra and footer via Snippet.
Render in current domDOM remains in place; The native top layer is not limited to the card.
Submit form in drawerValidation and submit from footer.
Preview drawerView and edit table member.
Multi-level drawerThe child panel pushes its parent by the configured distance.
Preset sizedefault 378px, large 736px and custom size.
maskControls the backdrop, its blur and whether clicking it closes the panel.
Closable placementPlaces the close button at the end of the header.
Custom semantic dom stylingUse classNames and styles to customize individual parts of the panel.

Drawer

PropertyDescriptionTypeDefault
closeIconThe close icon. With closable omitted, null hides the close button.DrawerCloseIcon—
defaultSizeInitial size when size is omitted.DrawerSize378
resizableDrag the edge to change the width or height.boolean | DrawerResizableConfigfalse
maxSizeMaximum size in pixels while dragging.number—
pushOffsets the parent panel when a child opens.boolean | DrawerPushConfig{ distance: 180 }
loadingShows a Skeleton in the body while loading.booleanfalse
drawerRenderReceives the panel section so it can be wrapped or replaced.Snippet<[section: Snippet]>—
panelRefUse bind:panelRef to access the section element.HTMLDivElement—
focusableTraps focus and optionally restores it to the trigger after closing.DrawerFocusableConfig—
autoFocusMoves focus into the panel on open.booleantrue
classNamesClasses for individual panel elements.DrawerSemantic—
stylesStyles for individual panel elements.DrawerSemantic—
rootStyleAdditional styles on the root dialog.string—
motionConfigures the transition for the selected edge.DrawerMotionConfig | (placement) => DrawerMotionConfig—
maskMotionConfigures the backdrop transition.DrawerMotionConfig—
zIndexSets the panel layer used by nested popups.number—
afterOpenChangeReports opening or closing when the transition completes.(open: boolean) => void—
prefixClsFull 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.stringConfigProvider.prefixCls + "-drawer"
openSupports bind:open.booleanfalse
titleTitle and available name of the panel.DrawerContent—
childrenMain content.Snippet—
extraAdditional actions in the header.DrawerContent—
footerActions below scrollable content.DrawerContent—
placementPhysical side of the screen.top | right | bottom | leftright
sizeWidth or height by placement; default 378px, large 736px.default | large | number | stringdefault
closableConfigures the close button, its icon and accessible name.DrawerClosabletrue
keyboardClosing by Escape.booleantrue
maskControls the backdrop, its blur and whether clicking it closes the panel.DrawerMaskclosable=true, blur=false
forceRenderMounts the content before the first opening.booleanfalse
destroyOnHiddenRemoves children after closing; the local state is reset.booleanfalse
getContainerContainer, getter, selector or false.GetContainerbody / ConfigProvider
onCloseUser close request event.(event: Event) => void—
classRoot native dialog class.string—
styleCSS 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.

Actual markings
ElementPurpose
dialog.ant-svelte-drawerThe root dialog receives class and style.
.ant-drawer-maskMask with pointer down/up and blur processing.
.ant-drawer-content-wrapperPanel geometry by placement and size.
.ant-drawer-sectionHeader, body and footer area.
.ant-drawer-headerHeading, standard cross and extra.
.ant-drawer-bodyScrollable content.
.ant-drawer-footerActions under the content.

Registration tokens

The draggerSize token sets the handle thickness when resizable is enabled.

TokenPurpose
zIndexPopupCSS layer of the root dialog; native top layer is preserved.
footerPaddingBlockVertical footer padding.
footerPaddingInlineHorizontal footer padding.
draggerSizeThickness of the draggable resize area.
Common tokens of the current topic
TokenMeaning
colorBgElevated#ffffff
colorBgMaskrgba(0,0,0,0.45)
colorTextHeadingrgba(0,0,0,0.88)
colorTextrgba(0,0,0,0.88)
fontSizeLG16
paddingLG24

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.

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.