Back to Ant Design

Drawer

components/drawer/index.en-US.md

6.3.76.9 KB
Original Source

When To Use

A Drawer is a panel that is typically overlaid on top of a page and slides in from the side. It contains a set of information or actions. Since the user can interact with the Drawer without leaving the current page, tasks can be achieved more efficiently within the same context.

  • Use a Form to create or edit a set of information.
  • Processing subtasks. When subtasks are too heavy for a Popover and we still want to keep the subtasks in the context of the main task, Drawer comes very handy.
  • When the same Form is needed in multiple places.

Notes for developers

Since the 5.17.0, we provided the loading prop by the Spin. However, since the 5.18.0 version, we have fixed this design error and replaced the Spin with the Skeleton, and also modified the type of loading prop, which can only accept boolean type.

Examples

<!-- prettier-ignore -->

<code src="./demo/basic-right.tsx">Basic</code> <code src="./demo/placement.tsx">Custom Placement</code> <code src="./demo/resizable.tsx" version="6.0.0">Resizable</code> <code src="./demo/loading.tsx" version="5.17.0">Loading</code> <code src="./demo/extra.tsx">Extra Actions</code> <code src="./demo/render-in-current.tsx">Render in current dom</code> <code src="./demo/form-in-drawer.tsx">Submit form in drawer</code> <code src="./demo/user-profile.tsx">Preview drawer</code> <code src="./demo/multi-level-drawer.tsx">Multi-level drawer</code> <code src="./demo/size.tsx">Preset size</code> <code src="./demo/mask.tsx">mask</code> <code src="./demo/closable-placement.tsx" version="5.28.0">Closable placement</code> <code src="./demo/style-class.tsx" version="6.0.0">Custom semantic dom styling</code> <code src="./demo/config-provider.tsx" debug>ConfigProvider</code> <code src="./demo/no-mask.tsx" debug>No mask</code> <code src="./demo/render-panel.tsx" debug>_InternalPanelDoNotUseOrYouWillBeFired</code> <code src="./demo/scroll-debug.tsx" debug>Scroll Debug</code> <code src="./demo/component-token.tsx" debug>Component Token</code>

API

Common props ref:Common props

PropertyDescriptionTypeDefaultVersion
afterOpenChangeCallback after the animation ends when switching drawersfunction(open)-
bodyStyleStyle of the drawer body, please use styles.body insteadCSSProperties--
classNameConfig Drawer Panel className. Use rootClassName if want to config top DOM stylestring-
classNamesCustomize class for each semantic structure inside the Drawer component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-
closableWhether to show a close button. The position can be configured with placementboolean | { closeIcon?: React.ReactNode; disabled?: boolean; placement?: 'start' | 'end' }trueplacement: 5.28.0
contentWrapperStyleStyle of the drawer wrapper, please use styles.wrapper insteadCSSProperties--
destroyOnCloseWhether to unmount child components on closing drawer or notbooleanfalse
destroyInactivePanelWhether to unmount child components on closing drawer or not, please use destroyOnHidden insteadbooleanfalse-
destroyOnHiddenWhether to unmount child components on closing drawer or notbooleanfalse5.25.0
drawerStyleStyle of the drawer panel, please use styles.section insteadCSSProperties--
extraExtra actions area at cornerReactNode-4.17.0
footerThe footer for DrawerReactNode-
footerStyleStyle of the drawer footer, please use styles.footer insteadCSSProperties--
forceRenderPre-render Drawer component forciblybooleanfalse
focusableConfiguration for focus management in the Drawer{ trap?: boolean, focusTriggerAfterClose?: boolean }-6.2.0
getContainermounted node and display window for DrawerHTMLElement | () => HTMLElement | Selectors | falsebody
headerStyleStyle of the drawer header part, please use styles.header insteadCSSProperties-
heightPlacement is top or bottom, height of the Drawer dialog, please use size insteadstring | number378
keyboardWhether support press esc to closebooleantrue
loadingShow the Skeletonbooleanfalse5.17.0
maskMask effectboolean | { enabled?: boolean, blur?: boolean, closable?: boolean }truemask.closable: 6.3.0
maskClosableClicking on the mask (area outside the Drawer) to close the Drawer or notbooleantrue
maskStyleStyle of the drawer mask, please use styles.mask insteadCSSProperties--
maxSizeMaximum size (width or height depending on placement) when resizablenumber-6.0.0
openWhether the Drawer dialog is visible or notbooleanfalse
placementThe placement of the Drawertop | right | bottom | leftright
pushNested drawers push behaviorboolean | { distance: string | number }{ distance: 180 }4.5.0+
resizableEnable resizable by draggingboolean | ResizableConfig-boolean: 6.1.0
rootStyleStyle of wrapper element which contains mask compare to styleCSSProperties-
sizepreset size of drawer, default 378px and large 736px, or a custom number'default' | 'large' | number | string'default'4.17.0, string: 6.2.0
styleStyle of Drawer panel. Use styles.body if want to config body onlyCSSProperties-
stylesCustomize inline style for each semantic structure inside the Drawer component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-
titleThe title for DrawerReactNode-
widthWidth of the Drawer dialog, please use size insteadstring | number378
zIndexThe z-index of the Drawernumber1000
onCloseSpecify a callback that will be called when a user clicks mask, close button or Cancel buttonfunction(e)-
drawerRenderCustom drawer content render(node: ReactNode) => ReactNode-5.18.0

ResizableConfig

PropertyDescriptionTypeDefaultVersion
onResizeStartCallback when resize starts() => void-6.0.0
onResizeCallback during resizing(size: number) => void-6.0.0
onResizeEndCallback when resize ends() => void-6.0.0

Semantic DOM

<code src="./demo/_semantic.tsx" simplify="true"></code>

Design Token

<ComponentTokenTable component="Drawer"></ComponentTokenTable>