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
Independent panels
The first panel is initially open; You can open several at the same time.
<script lang="ts">
import { Collapse } from '@woodger/antd';
</script>
<Collapse aria-label={("Independent panels")} headingLevel={4} defaultActiveKey={[
'one'
]} items={([
{ key: 'one', label: "Project Description", children: "Interface components for Svelte 5." },
{ key: 'two', label: "Installation", children: "Connect the public npm package and styles." },
{ key: 'three', label: "Limitations", children: "The composition of the API depends on the package version." }
])} />
Dimensions
small, medium and large change the padding of headings and content.
<script lang="ts">
import { Collapse, Select } from '@woodger/antd';
let size = $state<'small' | 'medium' | 'large'>('medium');
</script>
<style>.control { margin-bottom:16px; }</style>
<div
class="control"
><Select
aria-label={("Panel size")}
bind:value={size}
options={([
{ value: 'small', label: "Small" }, { value: 'medium', label: "Regular" }, {
value: 'large',
label: "Large"
}
])}
/></div>
<Collapse {size} headingLevel={4} defaultActiveKey={['one']} items={([
{ key: 'one', label: "Project parameters", children: "Fields and settings of one section." },
{ key: 'two', label: "History", children: "Changes and releases." }
])} />
["one"]
Accordion and binding
Only one panel is open; onChange in Svelte receives an array of string keys.
<script lang="ts">
import { Button, Collapse, type CollapseActiveKey } from '@woodger/antd';
let activeKey = $state<CollapseActiveKey | undefined>(['one']);
let changed = $state<string[]>(['one']);
</script>
<style>
.controls {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-bottom: 16px;
}
</style>
<div class="controls"><Button onclick={() => { activeKey = ['two']; }}>
{("Open installation")}
</Button><Button onclick={() => {
activeKey = [];
}}>{("Collapse all")}</Button></div>
<Collapse
aria-label={("Project Accordion")}
headingLevel={4}
accordion
bind:activeKey
onChange={keys => { changed = keys; }}
items={([
{ key: 'one', label: "Description", children: "Purpose of the project." },
{ key: 'two', label: "Installation", children: "Connecting components." },
{ key: 'three', label: "Check", children: "Check availability and behavior." }
])}
/>
<p role="status" aria-label={("Accordion Change")}>{JSON.stringify(changed)}</p>
Nested panels
Internal panels are independently controlled; Heading level increased.
<script lang="ts">
import { Collapse } from '@woodger/antd';
</script>
{#snippet nested()}<Collapse
headingLevel={5}
aria-label={("Project subsections")}
items={([
{ key: 'source', label: "Sources", children: "Components, types and styles." },
{ key: 'tests', label: "Tests", children: "Library consumer scripts." }
])}
/>{/snippet}
<Collapse headingLevel={4} defaultActiveKey={['project']} items={([
{ key: 'project', label: "Project", children: nested },
{ key: 'release', label: "Issue", children: "Verification and publication." }
])} />
Without frame
bordered=false removes the outer border and changes the body design.
<script lang="ts">
import { Collapse } from '@woodger/antd';
</script>
<Collapse headingLevel={4} bordered={false} defaultActiveKey={['one']} items={([
{ key: 'one', label: "Description", children: "Drop-down section without a common frame." },
{ key: 'two', label: "Delivery", children: "Terms and conditions of receipt." }
])} />
Own panel design
Element styles and expandIcon allow you to style panels separately.
<script lang="ts">
import { Collapse, type CollapseExpandIconInfo } from '@woodger/antd';
</script>
{#snippet arrow(info: CollapseExpandIconInfo)}<svg
width="14"
height="14"
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
stroke-width="2"
style={`transform:rotate(${info.isActive ? 90 : 0}deg)`}
aria-hidden="true"
><path d="m6 3 5 5-5 5" /></svg>{/snippet}
<Collapse
headingLevel={4}
bordered={false}
expandIcon={arrow}
defaultActiveKey={['one']}
items={([
{
key: 'one',
label: "Project materials",
children: "Description and files.",
style:
`
border: 0;
margin-bottom: 16px;
border-radius: 8px;
background: var(--ant-color-fill-alter);
`,
styles: { body: 'padding:16px' }
},
{
key: 'two',
label: "Discussions",
children: "Team decisions.",
style: `
border: 0;
border-radius: 8px;
background: var(--ant-color-fill-alter);
`,
styles: { body: 'padding:16px' }
}
])}
/>
Header icon
Passive Snippet with SVG and text inside a native button; without nested controls.
<script lang="ts">
import { Collapse } from '@woodger/antd';
</script>
{#snippet title()}<span
style="
display: inline-flex;
align-items: center;
gap: 8px;
"
><svg
viewBox="0 0 20 20"
width="18"
height="18"
fill="none"
stroke="currentColor"
aria-hidden="true"
><path
d="M3 3h14v14H3zM6 7h8M6 10h8M6 13h5"
/></svg><span>{("Project documents")}</span></span>{/snippet}
<Collapse headingLevel={4} items={([{
key: 'documents',
label: title,
children: "Requirements, solutions and instructions."
}])} />
Without arrow
showArrow=false hides the icon; the entire header button continues to work.
<script lang="ts">
import { Collapse } from '@woodger/antd';
</script>
<Collapse headingLevel={4} items={([
{
key: 'one',
label: "Section without arrow",
showArrow: false,
children: "Keyboard control retained."
},
{ key: 'two', label: "Regular section", children: "With visible deployment indicator." }
])} />
Saved: 0.
Additional action
The button in extra performs its own action, saving the state of the panel.
<script lang="ts">
import { Button, Collapse } from '@woodger/antd';
let saved = $state(0);
</script>
{#snippet extra()}
<Button
size="small"
style="
max-width: 100%;
min-width: 0;
height: auto;
min-height: var(--ant-control-height-sm);
white-space: normal;
"
aria-label={("Save section")}
onclick={() => { saved++; }}
>{("Save")}</Button>
{/snippet}
<Collapse headingLevel={4} defaultActiveKey={['one']} items={([
{ key: 'one', label: "Parameters", children: "The action on the right does not collapse the panel.", extra }
])} />
<p
role="status"
aria-label={("Saving partition")}
>{("Saved: ")}{saved}.</p>
Transparent panels
ghost removes the background and borders of panels; the backing of the container is visible.
<script lang="ts">
import { Collapse } from '@woodger/antd';
</script>
<style>
.surface {
padding: 16px;
background: var(--ant-color-fill-alter);
border-radius: 8px;
}
</style>
<div class="surface">
<Collapse headingLevel={4} ghost defaultActiveKey={['one']} items={([
{ key: 'one', label: "Description", children: "Transparent panel on a common substrate." },
{ key: 'two', label: "Details", children: "Additional information." }
])} />
</div>
Switching area
Regular title, only an arrow and an inaccessible panel.
<script lang="ts">
import { Collapse } from '@woodger/antd';
</script>
<Collapse headingLevel={4} items={([
{ key: 'header', label: "Entire title", children: "Opens by title." },
{
key: 'icon',
label: "Arrow only",
collapsible: 'icon',
children: "The arrow button has an accessible title name."
},
{
key: 'disabled',
label: "Inaccessible section",
collapsible: 'disabled',
children: "Contents of an inaccessible panel."
}
])} />
Semantic DOM
The shared styles accepts a function returning CSS objects. items[].styles customizes an individual panel.
<script lang="ts">
import { Collapse } from '@woodger/antd';
</script>
<Collapse headingLevel={4} defaultActiveKey={['one']} styles={({ props }) => ({
header: { background: props.bordered ? 'var(--ant-color-fill-alter)' : 'transparent' },
title: { fontWeight: 600 },
body: { lineHeight: 1.8 }
})} items={([
{ key: 'one', label: "General design", children: "Header and body styles." },
{
key: 'two', label: "Element settings", children: "Local body styles.", styles: {
body: { padding: '20px' },
title: { color: 'var(--ant-color-success-text)' }
}
}
])} />
Local topic
Collapse tokens set padding and background without changing the adjacent theme.
<script lang="ts">
import { Collapse, ConfigProvider } from '@woodger/antd';
</script>
<ConfigProvider theme={{
components: {
Collapse: {
headerPadding: '14px 20px',
contentPadding: '20px',
headerBg: 'var(--ant-color-fill-alter)',
contentBg: 'var(--ant-color-bg-container)',
borderlessContentPadding: '12px 20px',
borderlessContentBg: 'var(--ant-color-fill-alter)'
}
}
}}>
<Collapse id="collapse-token-panel" headingLevel={4} defaultActiveKey={['one']} items={([
{ key: 'one', label: "Local tokens", children: "Custom header and body indents." }
])} />
</ConfigProvider>
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.
<script lang="ts">
import { Checkbox, Collapse, Input } from '@woodger/antd';
let destroy = $state(false);
</script>
<style>.control { margin-bottom:16px; }</style>
{#snippet draft()}<Input
aria-label={("Draft inside the panel")}
defaultValue="Анна"
/>{/snippet}
<div
class="control"
><Checkbox
bind:checked={destroy}
>{("Remove hidden content")}</Checkbox></div>
<Collapse headingLevel={4} destroyOnHidden={destroy} defaultActiveKey={['draft']} items={([
{ key: 'draft', label: "Draft", children: draft }
])} />
Participant form
Saved review form: independent reset, nested fields and questionnaire submission.
<script lang="ts">
import {
Button,
Checkbox,
Collapse,
Input,
type CollapseActiveKey,
type CollapseTrigger
} from '@woodger/antd';
let activeKey = $state<CollapseActiveKey | undefined>(['contacts']);
let accordion = $state(false);
let destroyOnHidden = $state(false);
let ghost = $state(false);
let bordered = $state(true);
let collapsible = $state<CollapseTrigger>('header');
let expandIconPlacement = $state<'start' | 'end'>('start');
let revision = $state(0);
let result = $state(("Collapse the section and open it again - unsaved fields will remain in place."));
function save(event: SubmitEvent) {
event.preventDefault();
const data = new FormData(event.currentTarget as HTMLFormElement);
const name = data.get('contactName');
result = name === null
? ("Expand the “Contacts” section to fill out the form.")
: ("Questionnaire saved: " + String((name || ("without name"))) + ". News: " + String((data.has('news')
? ("included")
: ("switched off"))) + ".");
}
</script>
<style>
.settings {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
margin-bottom: 24px;
}
.settings label {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
select {
padding: 4px 8px;
color: var(--ant-color-text);
background: var(--ant-color-bg-container);
border: 1px solid var(--ant-color-border);
border-radius: 6px;
font: inherit;
}
.fields {
display: grid;
gap: 16px;
max-width: 360px;
}
.field {
display: grid;
gap: 6px;
}
.footer {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
margin-top: 24px;
}
output { color: var(--ant-color-text-secondary); }
</style>
{#snippet contacts()}
{#key revision}
<div class="fields"><label class="field">{("Contact name")}<Input
name="contactName"
defaultValue="Анна"
/></label><label
class="field"
>{("Comment to the questionnaire")}<Input
name="comment"
defaultValue="Новый участник"
/></label></div>
{/key}
{/snippet}
{#snippet preferences()}
{#key revision}
<Checkbox name="news" defaultChecked>
{("Receive profile news")}
</Checkbox>
{/key}
{/snippet}
{#snippet extra()}
<Button
size="small"
style="
max-width: 100%;
min-width: 0;
height: auto;
min-height: var(--ant-control-height-sm);
white-space: normal;
"
onclick={() => {
revision++;
result = ("The profile has been reset.");
}}
>{("Reset profile")}</Button>
{/snippet}
{#snippet additional()}{#key revision}<Collapse
aria-label={("Additional fields")}
headingLevel={5}
items={([
{ key: 'address', label: "Address", children: address },
{ key: 'help', label: "How data is used", children: help }
])}
/>{/key}{/snippet}
{#snippet address()}<label
class="field"
>{("Participant's city")}<Input
name="city"
defaultValue="Москва"
/></label>{/snippet}
{#snippet help()}<p>{("This is a demo questionnaire. The data remains on the page and is not sent to the server.")}</p>{/snippet}
<div class="settings">
<Checkbox bind:checked={accordion}>{("One open partition")}</Checkbox>
<Checkbox
bind:checked={destroyOnHidden}
>{("Reset content when hidden")}</Checkbox>
<Checkbox bind:checked={bordered}>{("Show frame")}</Checkbox>
<Checkbox bind:checked={ghost}>{("Transparent background")}</Checkbox>
<label>{("Switching area ")}<select
bind:value={collapsible}
><option
value="header"
>{("Header")}</option><option
value="icon"
>{("Arrow only")}</option><option
value="disabled"
>{("Disabled")}</option></select></label>
<label>{("Arrow position ")}<select
bind:value={expandIconPlacement}
><option
value="start"
>{("At the beginning")}</option><option
value="end"
>{("At the end")}</option></select></label>
</div>
<form onsubmit={save}>
<Collapse
aria-label={("Participant form")}
headingLevel={4}
bind:activeKey
{accordion}
{destroyOnHidden}
{collapsible}
{expandIconPlacement}
{bordered}
{ghost}
items={([
{ key: 'contacts', label: "Contacts", children: contacts, extra },
{ key: 'preferences', label: "Notifications", children: preferences },
{ key: 'additional', label: "Additional", children: additional },
{ key: 'access', label: "Access rights", collapsible: 'disabled' }
])}
/>
<div
class="footer"
><Button
htmlType="submit"
type="primary"
>{("Save profile")}</Button><output
aria-label={("Questionnaire result")}
>{result}</output></div>
</form>
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.
| Theme | Example or limitation |
|---|---|
| Collapse | Independent disclosure. |
| Size | Three sizes. |
| Accordion | Controllable one panel. |
| Nested panel | Nesting and heading levels. |
| Borderless | Without external frame. |
| Custom Panel | Element styles and custom arrow. |
| Panel with icon | SVG and title text. |
| No arrow | Without arrow. |
| Extra node | Independent action. |
| Ghost Collapse | Transparent backing. |
| Collapsible | header, icon, disabled. |
| Custom semantic dom styling | General and local slots. |
| Property | Description | Type | Default |
|---|---|---|---|
prefixCls | Full local CSS prefix for Collapse and its panels. The empty string and undefined inherit ConfigProvider.prefixCls; default is ant-collapse. | string | ConfigProvider + -collapse |
items | An array of panels with titles, content and expansion settings. | readonly CollapseItem[] | — |
activeKey | bind:activeKey: number, string or list. | CollapseActiveKey | — |
defaultActiveKey | Initial expansion of an unmanaged component. | CollapseActiveKey | — |
onChange | Always an array of string keys, including accordion. | (keys: string[]) => void | — |
accordion | Only one open panel. | boolean | false |
size | small, medium, large. | ComponentSize | context / medium |
bordered | General frame. | boolean | true |
ghost | Transparent panels without frame. | boolean | false |
collapsible | Switching area; item can clarify the meaning. | header | icon | disabled | header |
expandIconPlacement | Arrow position. | start | end | start |
expandIcon | Own hand; the rotation is set by Snippet. | Snippet<[CollapseExpandIconInfo]> | — |
destroyOnHidden | Remove hidden body; forceRender of the element preserves it. | boolean | false |
headingLevel | Title level of native buttons. | 2 | 3 | 4 | 5 | 6 | 3 |
styles | CSS strings and objects for panel parts. Accepts an object or a function of the component props. | CollapseSemantic<CSSStyle> | — |
classNames | Classes of common slots. | CollapseSemantic | — |
nativeElement | bind: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.
| Token | Purpose |
|---|---|
borderlessContentBg | Body background without frame. |
borderlessContentPadding | Body indents without frame. |
contentBg | Body background. |
contentPadding | Normal body indents. |
contentPaddingLG | Large body indents. |
contentPaddingSM | Small body indents. |
headerBg | Header background. |
headerPadding | Normal header indents. |
headerPaddingLG | Large header indents. |
headerPaddingSM | Small header indents. |
| Token | Current value |
|---|---|
colorText | rgba(0,0,0,0.88) |
colorTextHeading | rgba(0,0,0,0.88) |
colorBorder | #d9d9d9 |
colorFillAlter | rgba(0,0,0,0.02) |
borderRadiusLG | 8 |
fontSize | 14 |
lineHeight | 1.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.