JGuang

Drawer

Drawer · Ant Design

Preview
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Drawer

A panel that slides out from the edge of the screen.

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

  • Basic · basic-right
  • Custom Placement · placement
  • Resizable · resizable
  • Loading · loading
  • Extra Actions · extra
  • Render in current dom · render-in-current
  • Submit form in drawer · form-in-drawer
  • Preview drawer · user-profile
  • Multi-level drawer · multi-level-drawer
  • Preset size · size
  • mask · mask
  • Closable placement · closable-placement
  • Custom semantic dom styling · style-class

API

Common props ref:Common props

PropertyDescriptionTypeDefaultVersionGlobal Config
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-5.7.0
classNamesCustomize class for each semantic structure inside the Drawer component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-5.10.0
closableWhether to show a close button. The position can be configured with placementboolean | { closeIcon?: React.ReactNode; disabled?: boolean; placement?: 'start' | 'end' }trueplacement: 5.28.05.15.0, placement: 6.1.1
contentWrapperStyleStyle of the drawer wrapper, please use styles.wrapper insteadCSSProperties--×
destroyOnCloseWhether 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.06.4.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.06.0.0, mask.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-5.7.0
stylesCustomize inline style for each semantic structure inside the Drawer component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-5.10.0
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

Semantic nodeNative descriptionVersion
rootRoot element with fixed positioning, z-index control, pointer events, color and other basic styles and layout control for drawer container6.0.0
maskMask element with absolute positioning, z-index, background color, pointer events and other mask layer styles and interaction controls5.13.0
sectionDrawer container element with flex layout, width/height, overflow control, background color, pointer events and other drawer body styles6.0.0
headerHeader element with flex layout, alignment, padding, font size, line height, bottom border and other header area styles5.13.0
titleTitle element with flex ratio, margin, font weight, font size, line height and other title text styles6.0.0
extraExtra element with flex fixed layout and other additional operation content style controls6.0.0
bodyBody element with flex ratio, minimum size, padding, overflow scroll and other content area display and layout styles5.13.0
footerFooter element with flex shrink, padding, top border and other bottom operation area styles5.13.0
draggerDragger element used to resize the drawer, with absolute positioning, transparent background, pointer events control, hover state styles, and dragging state styles6.0.0
closeClose button element with basic button styling6.1.0

Semantic description source: vendor/components/drawer/demo/_semantic.tsx

Design Token

Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.

TokenTypeNative description
zIndexPopupnumberz-index of drawer
footerPaddingBlocknumberVertical padding of footer
footerPaddingInlinenumberHorizontal padding of footer
draggerSizenumberSize of resize handle

Declaration source: vendor/components/drawer/style/index.ts

import type { CSSObject } from '@ant-design/cssinjs';

import { unit } from '@ant-design/cssinjs';

import { genFocusStyle } from '../../style';

import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';

import { genStyleHooks, mergeToken } from '../../theme/internal';

import genMotionStyle from './motion';

export interface ComponentToken {
  /**
   * @desc 弹窗 z-index
   * @descEN z-index of drawer
   */
  zIndexPopup: number;
  /**
   * @desc 底部区域纵向内间距
   * @descEN Vertical padding of footer
   */
  footerPaddingBlock: number;
  /**
   * @desc 底部区域横向内间距
   * @descEN Horizontal padding of footer
   */
  footerPaddingInline: number;
  /**
   * @desc 拖拽手柄大小
   * @descEN Size of resize handle
   */
  draggerSize: number;
}

export interface DrawerToken extends FullToken<'Drawer'> {}

Shared native props

Tips: The following generic properties apply to most antd components; those not supported are described separately.

PropertyDescriptionTypeDefault
styleThe additional styleCSSProperties-
classNameThe additional css classstring-
rootClassNameClassName on the root elementstring-
autoFocusAuto focus when component mounted, only effective for focusable elements like forms, links, etc.booleanfalse

Install and reproduce an example

npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.

Native type references

The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.

  • vendor/components/drawer/Drawer.tsx
  • vendor/components/drawer/DrawerPanel.tsx
  • vendor/components/drawer/style/index.ts
  • vendor/components/drawer/style/motion.ts
  • vendor/components/drawer/useFocusable.ts

Source and license

https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd

Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.