JGuang

Collapse

Collapse · Ant Design

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

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.
  • Accordion is a special kind of Collapse, 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

PropertyDescriptionTypeDefaultVersionGlobal Config
accordionIf true, Collapse renders as Accordionbooleanfalse×
activeKeyKey of the active panelstring[] | string <br/> number[] | numberNo default value. In accordion mode, it's the key of the first panel×
borderedToggles rendering of the border around the collapse blockbooleantrue×
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-6.0.0
collapsibleSpecify how to trigger Collapse. Either by clicking icon or by clicking any area in header or disable collapse functionality itselfheader | icon | disabled-4.9.0×
defaultActiveKeyKey of the initial active panelstring[] | string <br/> number[] | number-×
destroyInactivePanelDestroy Inactive Panelbooleanfalse×
destroyOnHiddenDestroy Inactive Panelbooleanfalse5.25.0×
expandIconCustomize the collapse expand icon(panelProps) => ReactNode-5.15.0
expandIconPlacementSet expand icon placementstart | endstart-×
expandIconPositionSet expand icon position, Please use expandIconPlacement insteadstart | end-4.21.0×
ghostMake the collapse borderless and its background transparentbooleanfalse4.4.0×
sizeSet the size of collapselarge | medium | smallmedium5.2.0×
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-6.0.0
onChangeCallback function executed when active panel is changedfunction-×
itemscollapse items contentItemType-5.6.0×

ItemType

PropertyDescriptionTypeDefaultVersion
classNamesSemantic structure classNameRecord<header | body, string>-5.21.0
collapsibleSpecify whether the panel be collapsible or the trigger area of collapsibleheader | icon | disabled-
childrenBody area contentReactNode-
extraThe extra element in the cornerReactNode-
forceRenderForced render of content on panel, instead of lazy rendering after clicking on headerbooleanfalse
keyUnique key identifying the panel from among its siblingsstring | number-
labelTitle of the panelReactNode--
showArrowIf false, panel will not show arrow icon. If false, collapsible can't be set as iconbooleantrue
stylesSemantic DOM styleRecord<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. :::

PropertyDescriptionTypeDefaultVersion
collapsibleSpecify whether the panel be collapsible or the trigger area of collapsibleheader | icon | disabled-4.9.0 (icon: 4.24.0)
extraThe extra element in the cornerReactNode-
forceRenderForced render of content on panel, instead of lazy rendering after clicking on headerbooleanfalse
headerTitle of the panelReactNode-
keyUnique key identifying the panel from among its siblingsstring | number-
showArrowIf false, panel will not show arrow icon. If false, collapsible can't be set as iconbooleantrue

Semantic DOM

Semantic nodeNative descriptionVersion
rootRoot element with border, border-radius, background color and container styles that control the overall layout and appearance of collapse panels6.0.0
headerHeader element with flex layout, padding, color, line-height, cursor style, transition animations and other interactive styles for panel headers5.21.0
iconIcon element with font size, transition animations, rotation transforms and other styles and animations for expand/collapse arrows6.0.0
titleTitle element with flex auto layout and margin styles for title text layout and typography6.0.0
bodyBody element with padding, color, background color and other styles for panel content area display5.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.

TokenTypeNative description
headerPaddingCSSProperties['padding']Padding of header
headerPaddingSMCSSProperties['padding']Padding of small header
headerPaddingLGCSSProperties['padding']Padding of large header
headerBgstringBackground of header
contentPaddingCSSProperties['padding']Padding of content
contentPaddingSMCSSProperties['padding']Padding of small content
contentPaddingLGCSSProperties['padding']Padding of large content
contentBgstringBackground of content
borderlessContentPaddingCSSProperties['padding']Padding of content in borderless style
borderlessContentBgstringBackground 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.

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/collapse/Collapse.tsx
  • vendor/components/collapse/CollapsePanel.tsx
  • vendor/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.