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 theloadingprop by the Spin. However, since the5.18.0version, we have fixed this design error and replaced the Spin with the Skeleton, and also modified the type ofloadingprop, which can only acceptbooleantype.
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
| Property | Description | Type | Default | Version | Global Config |
|---|---|---|---|---|---|
| afterOpenChange | Callback after the animation ends when switching drawers | function(open) | - | × | |
Style of the drawer body, please use styles.body instead | CSSProperties | - | - | × | |
| className | Config Drawer Panel className. Use rootClassName if want to config top DOM style | string | - | 5.7.0 | |
| classNames | Customize class for each semantic structure inside the Drawer component. Supports object or function. | Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string> | - | 5.10.0 | |
| closable | Whether to show a close button. The position can be configured with placement | boolean | { closeIcon?: React.ReactNode; disabled?: boolean; placement?: 'start' | 'end' } | true | placement: 5.28.0 | 5.15.0, placement: 6.1.1 |
Style of the drawer wrapper, please use styles.wrapper instead | CSSProperties | - | - | × | |
Whether to unmount child components on closing drawer or not, please use destroyOnHidden instead | boolean | false | × | ||
| destroyOnHidden | Whether to unmount child components on closing drawer or not | boolean | false | 5.25.0 | × |
Style of the drawer panel, please use styles.section instead | CSSProperties | - | - | × | |
| extra | Extra actions area at corner | ReactNode | - | 4.17.0 | × |
| footer | The footer for Drawer | ReactNode | - | × | |
Style of the drawer footer, please use styles.footer instead | CSSProperties | - | - | × | |
| forceRender | Pre-render Drawer component forcibly | boolean | false | × | |
| focusable | Configuration for focus management in the Drawer | { trap?: boolean, focusTriggerAfterClose?: boolean } | - | 6.2.0 | 6.4.0 |
| getContainer | mounted node and display window for Drawer | HTMLElement | () => HTMLElement | Selectors | false | body | × | |
Style of the drawer header part, please use styles.header instead | CSSProperties | - | × | ||
Placement is top or bottom, height of the Drawer dialog, please use size instead | string | number | 378 | × | ||
| keyboard | Whether support press esc to close | boolean | true | × | |
| loading | Show the Skeleton | boolean | false | 5.17.0 | × |
| mask | Mask effect | boolean | { enabled?: boolean, blur?: boolean, closable?: boolean } | true | mask.closable: 6.3.0 | 6.0.0, mask.closable: 6.3.0 |
| Clicking on the mask (area outside the Drawer) to close the Drawer or not | boolean | true | × | ||
Style of the drawer mask, please use styles.mask instead | CSSProperties | - | - | × | |
| maxSize | Maximum size (width or height depending on placement) when resizable | number | - | 6.0.0 | × |
| open | Whether the Drawer dialog is visible or not | boolean | false | × | |
| placement | The placement of the Drawer | top | right | bottom | left | right | × | |
| push | Nested drawers push behavior | boolean | { distance: string | number } | { distance: 180 } | 4.5.0+ | × |
| resizable | Enable resizable by dragging | boolean | ResizableConfig | - | boolean: 6.1.0 | × |
| rootStyle | Style of wrapper element which contains mask compare to style | CSSProperties | - | × | |
| size | preset size of drawer, default 378px and large 736px, or a custom number | 'default' | 'large' | number | string | 'default' | 4.17.0, string: 6.2.0 | × |
| style | Style of Drawer panel. Use styles.body if want to config body only | CSSProperties | - | 5.7.0 | |
| styles | Customize 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 | |
| title | The title for Drawer | ReactNode | - | × | |
Width of the Drawer dialog, please use size instead | string | number | 378 | × | ||
| zIndex | The z-index of the Drawer | number | 1000 | × | |
| onClose | Specify a callback that will be called when a user clicks mask, close button or Cancel button | function(e) | - | × | |
| drawerRender | Custom drawer content render | (node: ReactNode) => ReactNode | - | 5.18.0 | × |
ResizableConfig
| Property | Description | Type | Default | Version |
|---|---|---|---|---|
| onResizeStart | Callback when resize starts | () => void | - | 6.0.0 |
| onResize | Callback during resizing | (size: number) => void | - | 6.0.0 |
| onResizeEnd | Callback when resize ends | () => void | - | 6.0.0 |
Semantic DOM
| Semantic node | Native description | Version |
|---|---|---|
root | Root element with fixed positioning, z-index control, pointer events, color and other basic styles and layout control for drawer container | 6.0.0 |
mask | Mask element with absolute positioning, z-index, background color, pointer events and other mask layer styles and interaction controls | 5.13.0 |
section | Drawer container element with flex layout, width/height, overflow control, background color, pointer events and other drawer body styles | 6.0.0 |
header | Header element with flex layout, alignment, padding, font size, line height, bottom border and other header area styles | 5.13.0 |
title | Title element with flex ratio, margin, font weight, font size, line height and other title text styles | 6.0.0 |
extra | Extra element with flex fixed layout and other additional operation content style controls | 6.0.0 |
body | Body element with flex ratio, minimum size, padding, overflow scroll and other content area display and layout styles | 5.13.0 |
footer | Footer element with flex shrink, padding, top border and other bottom operation area styles | 5.13.0 |
dragger | Dragger element used to resize the drawer, with absolute positioning, transparent background, pointer events control, hover state styles, and dragging state styles | 6.0.0 |
close | Close button element with basic button styling | 6.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.
| Token | Type | Native description |
|---|---|---|
zIndexPopup | number | z-index of drawer |
footerPaddingBlock | number | Vertical padding of footer |
footerPaddingInline | number | Horizontal padding of footer |
draggerSize | number | Size 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.
| Property | Description | Type | Default |
|---|---|---|---|
| style | The additional style | CSSProperties | - |
| className | The additional css class | string | - |
| rootClassName | ClassName on the root element | string | - |
| autoFocus | Auto focus when component mounted, only effective for focusable elements like forms, links, etc. | boolean | false |
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.tsxvendor/components/drawer/DrawerPanel.tsxvendor/components/drawer/style/index.tsvendor/components/drawer/style/motion.tsvendor/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.