Ant Design Svelte

Collapse

Expandable panels, accordion, nesting, actions, preserved fields, and theme configuration.

When to use

Collapse reveals additional details upon request. It is suitable for FAQ, settings and long form when not all sections are needed at the same time. accordion leaves one panel open; regular Collapse allows several.

Panels and selected keys

items specifies the label, children and persistent key of each panel. defaultActiveKey defines the initial state, bind:activeKey binds the opening to the application. Numbers are compared using their string representation; onChange always receives string[], including in accordion.

Problem Opportunity Example
Expand multiple sections items, defaultActiveKey Independent disclosure
Leave one panel open accordion, bind:activeKey Accordion
Attach your own sections another Collapse Attachment
Change activation area collapsible Opening area
Manage field saving destroyOnHidden Life cycle

collapsible selects header, icon or disabled. The item setting specifies the general mode. showArrow: false hides the arrow; This does not work with opening only via icon. expandIcon - snippet with panel data and isActive; the native icon does not receive automatic rotation.

Content, actions and life cycle

label is located inside the native header button. Keep it passive: text, decorative icon, signature markup. Place interactive controls in extra or children. extra is a separate scope that should not switch the panel.

By default, the body is created when first expanded and saved after hiding. destroyOnHidden removes it on close, so local fields reappear. forceRender of a specific item creates and saves its contents regardless of lazy mode. For a draft that needs to survive DOM removal, store values ​​above Collapse.

Nested panels are controlled independently. headingLevel sets the heading level, default is 3; at a nested level, select the next appropriate document level. Opening a panel does not mean validating its fields: validation remains the responsibility of the Form or application.

Appearance and availability

size accepts small/medium/large and inherits the overall size. Bordered:false removes the outer border, ghost also removes the background and border design. expandIconPlacement uses logical start/end.

The native button provides Enter/Space, aria-expanded and connection to the body. The hidden body should not be the only place where an error is reported if the panel is closed. Keep a visible indication of problems in the header or open the relevant section when checking.

ConfigProvider.collapse sets the design and general arrow. Semantic header refers to the button, body refers to the internal content. Item classNames complement common classes, item styles override the shared styles. Both CSS strings and objects are supported. Collapse design tokens control padding and background.

A non-empty local prefixCls specifies the CSS classes of Collapse and its panels. The empty string and undefined inherit ConfigProvider.prefixCls with the -collapse suffix, defaulting to ant-collapse. Updating prefix preserves expansion, DOM fields and their values, focus and selection. Example ConfigProvider shows local exception and editor inside open panel.

Examples

Interface components for Svelte 5.

Independent panels

The first panel is initially open; You can open several at the same time.

Fields and settings of one section.

Dimensions

small, medium and large change the padding of headings and content.

Purpose of the project.

["one"]

Accordion and binding

Only one panel is open; onChange in Svelte receives an array of string keys.

Nested panels

Internal panels are independently controlled; Heading level increased.

Drop-down section without a common frame.

Without frame

bordered=false removes the outer border and changes the body design.

Description and files.

Own panel design

Element styles and expandIcon allow you to style panels separately.

Header icon

Passive Snippet with SVG and text inside a native button; without nested controls.

Without arrow

showArrow=false hides the icon; the entire header button continues to work.

The action on the right does not collapse the panel.

Saved: 0.

Additional action

The button in extra performs its own action, saving the state of the panel.

Transparent panel on a common substrate.

Transparent panels

ghost removes the background and borders of panels; the backing of the container is visible.

Switching area

Regular title, only an arrow and an inaccessible panel.

Header and body styles.

Semantic DOM

The shared styles accepts a function returning CSS objects. items[].styles customizes an individual panel.

Custom header and body indents.

Local topic

Collapse tokens set padding and background without changing the adjacent theme.

Saving and deleting content

Panels animate height and opacity. With destroyOnHidden, a closed panel removes its field after the animation and recreates it on reopening.

Participant form

Saved review form: independent reset, nested fields and questionnaire submission.

API

Examples are checked against the current ant.design page and the public API of the installed package. Full definitions of Props are in @woodger/antd.

Topics of official examples
ThemeExample or limitation
CollapseIndependent disclosure.
SizeThree sizes.
AccordionControllable one panel.
Nested panelNesting and heading levels.
BorderlessWithout external frame.
Custom PanelElement styles and custom arrow.
Panel with iconSVG and title text.
No arrowWithout arrow.
Extra nodeIndependent action.
Ghost CollapseTransparent backing.
Collapsibleheader, icon, disabled.
Custom semantic dom stylingGeneral and local slots.
Main parameters of Collapse
PropertyDescriptionTypeDefault
prefixClsFull local CSS prefix for Collapse and its panels. The empty string and undefined inherit ConfigProvider.prefixCls; default is ant-collapse.stringConfigProvider + -collapse
itemsAn array of panels with titles, content and expansion settings.readonly CollapseItem[]—
activeKeybind:activeKey: number, string or list.CollapseActiveKey—
defaultActiveKeyInitial expansion of an unmanaged component.CollapseActiveKey—
onChangeAlways an array of string keys, including accordion.(keys: string[]) => void—
accordionOnly one open panel.booleanfalse
sizesmall, medium, large.ComponentSizecontext / medium
borderedGeneral frame.booleantrue
ghostTransparent panels without frame.booleanfalse
collapsibleSwitching area; item can clarify the meaning.header | icon | disabledheader
expandIconPlacementArrow position.start | endstart
expandIconOwn hand; the rotation is set by Snippet.Snippet<[CollapseExpandIconInfo]>—
destroyOnHiddenRemove hidden body; forceRender of the element preserves it.booleanfalse
headingLevelTitle level of native buttons.2 | 3 | 4 | 5 | 63
stylesCSS strings and objects for panel parts. Accepts an object or a function of the component props.CollapseSemantic<CSSStyle>—
classNamesClasses of common slots.CollapseSemantic—
nativeElementbind:nativeElement instead of React ref.HTMLDivElement—

CollapseItem

key specifies a stable key; label is the passive content of the header, children is the body, extra is a separate action. collapsible, showArrow, forceRender, destroyOnHidden, styles/classNames and onItemClick are available. The missing key uses the string index; For a mutable list, specify the keys explicitly.

Semantic DOM

Root is a named group; headers use h2–h6 with native buttons and aria-expanded/aria-controls. Place interactive controls in extra or body, not in label.

Slots: root, header, title, icon, body. Header refers to the button, body refers to the internal content of the panel. Item styles complement the common ones and take precedence in matching CSS properties.

Registration tokens

theme.components.Collapse applies ten component tokens. ConfigProvider.collapse defines the general class/style, semantic slots and expandIcon. Local props and custom styles retain priority.

Component tokens
TokenPurpose
borderlessContentBgBody background without frame.
borderlessContentPaddingBody indents without frame.
contentBgBody background.
contentPaddingNormal body indents.
contentPaddingLGLarge body indents.
contentPaddingSMSmall body indents.
headerBgHeader background.
headerPaddingNormal header indents.
headerPaddingLGLarge header indents.
headerPaddingSMSmall header indents.
Common tokens of the current topic
TokenCurrent value
colorTextrgba(0,0,0,0.88)
colorTextHeadingrgba(0,0,0,0.88)
colorBorder#d9d9d9
colorFillAlterrgba(0,0,0,0.02)
borderRadiusLG8
fontSize14
lineHeight1.5714285714285714

FAQ

How to save a draft when closing?

Without destroyOnHidden, the visited body remains mounted. For DOM independence, store data above Collapse.

Where to put the additional button?

In extra. The label should remain the passive content of the title button.

Why does onChange return an array in accordion?

This is the Svelte API contract: callback always receives string[]. accordion limits the number of public keys.

How to choose regular size?

Use medium or the general ConfigProvider size. small and large change the padding.