Collapse
A content area which can be collapsed and expanded.
When To Use
- Can be used to group or hide complex regions to keep the page clean.
Accordionis a special kind ofCollapse, which allows only one panel to be expanded at a time.
Examples
- Collapse ·
basic - Size ·
size - Accordion ·
accordion - Nested panel ·
mix - Borderless ·
borderless - Custom Panel ·
custom - Panel with icon ·
icon - No arrow ·
noarrow - Extra node ·
extra - Ghost Collapse ·
ghost - Collapsible ·
collapsible - Custom semantic dom styling ·
style-class
API
Common props ref:Common props
Collapse
| Property | Description | Type | Default | Version | Global Config |
|---|---|---|---|---|---|
| accordion | If true, Collapse renders as Accordion | boolean | false | × | |
| activeKey | Key of the active panel | string[] | string <br/> number[] | number | No default value. In accordion mode, it's the key of the first panel | × | |
| bordered | Toggles rendering of the border around the collapse block | boolean | true | × | |
| classNames | Customize class for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string> | - | 6.0.0 | |
| collapsible | Specify how to trigger Collapse. Either by clicking icon or by clicking any area in header or disable collapse functionality itself | header | icon | disabled | - | 4.9.0 | × |
| defaultActiveKey | Key of the initial active panel | string[] | string <br/> number[] | number | - | × | |
| Destroy Inactive Panel | boolean | false | × | ||
| destroyOnHidden | Destroy Inactive Panel | boolean | false | 5.25.0 | × |
| expandIcon | Customize the collapse expand icon | (panelProps) => ReactNode | - | 5.15.0 | |
| expandIconPlacement | Set expand icon placement | start | end | start | - | × |
Set expand icon position, Please use expandIconPlacement instead | start | end | - | 4.21.0 | × | |
| ghost | Make the collapse borderless and its background transparent | boolean | false | 4.4.0 | × |
| size | Set the size of collapse | large | medium | small | medium | 5.2.0 | × |
| styles | Customize inline style for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties> | - | 6.0.0 | |
| onChange | Callback function executed when active panel is changed | function | - | × | |
| items | collapse items content | ItemType | - | 5.6.0 | × |
ItemType
| Property | Description | Type | Default | Version |
|---|---|---|---|---|
| classNames | Semantic structure className | Record<header | body, string> | - | 5.21.0 |
| collapsible | Specify whether the panel be collapsible or the trigger area of collapsible | header | icon | disabled | - | |
| children | Body area content | ReactNode | - | |
| extra | The extra element in the corner | ReactNode | - | |
| forceRender | Forced render of content on panel, instead of lazy rendering after clicking on header | boolean | false | |
| key | Unique key identifying the panel from among its siblings | string | number | - | |
| label | Title of the panel | ReactNode | - | - |
| showArrow | If false, panel will not show arrow icon. If false, collapsible can't be set as icon | boolean | true | |
| styles | Semantic DOM style | Record<header | body, CSSProperties> | - | 5.21.0 |
Collapse.Panel
:::warning{title=Deprecated}
When using version >= 5.6.0, we prefer to configuring the panel by items.
:::
| Property | Description | Type | Default | Version |
|---|---|---|---|---|
| collapsible | Specify whether the panel be collapsible or the trigger area of collapsible | header | icon | disabled | - | 4.9.0 (icon: 4.24.0) |
| extra | The extra element in the corner | ReactNode | - | |
| forceRender | Forced render of content on panel, instead of lazy rendering after clicking on header | boolean | false | |
| header | Title of the panel | ReactNode | - | |
| key | Unique key identifying the panel from among its siblings | string | number | - | |
| showArrow | If false, panel will not show arrow icon. If false, collapsible can't be set as icon | boolean | true |
Semantic DOM
| Semantic node | Native description | Version |
|---|---|---|
root | Root element with border, border-radius, background color and container styles that control the overall layout and appearance of collapse panels | 6.0.0 |
header | Header element with flex layout, padding, color, line-height, cursor style, transition animations and other interactive styles for panel headers | 5.21.0 |
icon | Icon element with font size, transition animations, rotation transforms and other styles and animations for expand/collapse arrows | 6.0.0 |
title | Title element with flex auto layout and margin styles for title text layout and typography | 6.0.0 |
body | Body element with padding, color, background color and other styles for panel content area display | 5.21.0 |
Semantic description source: vendor/components/collapse/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 |
|---|---|---|
headerPadding | CSSProperties['padding'] | Padding of header |
headerPaddingSM | CSSProperties['padding'] | Padding of small header |
headerPaddingLG | CSSProperties['padding'] | Padding of large header |
headerBg | string | Background of header |
contentPadding | CSSProperties['padding'] | Padding of content |
contentPaddingSM | CSSProperties['padding'] | Padding of small content |
contentPaddingLG | CSSProperties['padding'] | Padding of large content |
contentBg | string | Background of content |
borderlessContentPadding | CSSProperties['padding'] | Padding of content in borderless style |
borderlessContentBg | string | Background of content in borderless style |
Declaration source: vendor/components/collapse/style/index.ts
import type { CSSProperties } from 'react';
import type { CSSObject } from '@ant-design/cssinjs';
import { unit } from '@ant-design/cssinjs';
import { genFocusStyle, resetComponent, resetIcon } from '../../style';
import { genCollapseMotion } from '../../style/motion';
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
import { genStyleHooks, mergeToken } from '../../theme/internal';
/** Component only token. Which will handle additional calculation of alias token */
export interface ComponentToken {
// Component token here
/**
* @desc 折叠面板头部内边距
* @descEN Padding of header
*/
headerPadding: CSSProperties['padding'];
/**
* @desc 小号折叠面板头部内边距
* @descEN Padding of small header
*/
headerPaddingSM: CSSProperties['padding'];
/**
* @desc 大号折叠面板头部内边距
* @descEN Padding of large header
*/
headerPaddingLG: CSSProperties['padding'];
/**
* @desc 折叠面板头部背景
* @descEN Background of header
*/
headerBg: string;
/**
* @desc 折叠面板内容内边距
* @descEN Padding of content
*/
contentPadding: CSSProperties['padding'];
/**
* @desc 小号折叠面板内容内边距
* @descEN Padding of small content
*/
contentPaddingSM: CSSProperties['padding'];
/**
* @desc 大号折叠面板内容内边距
* @descEN Padding of large content
*/
contentPaddingLG: CSSProperties['padding'];
/**
* @desc 折叠面板内容背景
* @descEN Background of content
*/
contentBg: string;
/**
* @desc 简约风格折叠面板的内容内边距
* @descEN Padding of content in borderless style
*/
borderlessContentPadding: CSSProperties['padding'];
/**
* @desc 简约风格折叠面板的内容背景
* @descEN Background of content in borderless style
*/
borderlessContentBg: string;
}
type CollapseToken = FullToken<'Collapse'> & {
/**
* @desc 折叠面板边框圆角
* @descEN Border radius of collapse panel
*/
collapsePanelBorderRadius: number;
};
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/collapse/Collapse.tsxvendor/components/collapse/CollapsePanel.tsxvendor/components/collapse/style/index.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.