Back to Ant Design

Collapse

components/collapse/index.en-US.md

6.4.45.0 KB
Original Source

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

<!-- prettier-ignore -->

<code src="./demo/basic.tsx">Collapse</code> <code src="./demo/size.tsx">Size</code> <code src="./demo/accordion.tsx">Accordion</code> <code src="./demo/mix.tsx">Nested panel</code> <code src="./demo/borderless.tsx">Borderless</code> <code src="./demo/custom.tsx">Custom Panel</code> <code src="./demo/noarrow.tsx">No arrow</code> <code src="./demo/extra.tsx">Extra node</code> <code src="./demo/ghost.tsx">Ghost Collapse</code> <code src="./demo/collapsible.tsx">Collapsible</code> <code src="./demo/style-class.tsx" version="6.0.0">Custom semantic dom styling</code> <code src="./demo/component-token.tsx" debug>Component Token</code>

API

Common props ref:Common props

Collapse

PropertyDescriptionTypeDefaultVersionGlobal Config
accordionIf true, Collapse renders as Accordionbooleanfalse×
activeKeyKey of the active panelstring[] | string
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
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

<!-- prettier-ignore -->

:::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

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

Design Token

<ComponentTokenTable component="Collapse"></ComponentTokenTable>