Create

General

Collapsible

Copy page View as Markdown Open in ChatGPT Open in Claude

An interactive component which expands/collapses a panel.

Usage#

app.component.ts
import { WDS_COLLAPSIBLE } from '@wds/angular/collapsible';

Examples#

Default#

The trigger and the content can sit anywhere inside wds-collapsible, for example the trigger in a header. They belong to the nearest wds-collapsible, so panels can be nested.

@peduarte starred 3 repositories

@radix-ui/primitives
@radix-ui/colors
@stitches/react

Disabled#

disabled disables the trigger; the panel keeps its current state.

Can't toggle
The trigger is disabled, so the panel stays exactly as it was rendered.

Controlled#

The app keeps the state: open sets it, wds-open-change reports a change made with the trigger. Setting open from code does not fire the event.

The panel is openClose from outside
Toggle from inside
Both buttons change the same state, so the panel always matches the app.

API References#

wds-collapsible#

An expandable panel. wds-collapsible holds the state, a click on wds-collapsible-trigger toggles it, and wds-collapsible-content expands smoothly. Both parts can be nested at any depth (e.g. the trigger in a header); they belong to the nearest wds-collapsible, so panels can be nested.

Attributes

AttributeTypeDefaultDescription
openbooleanfalseWhether the panel is open. Setting it from code does not fire wds-open-change.
disabledbooleanfalseBlocks toggling: the trigger is disabled and the panel keeps its current state.

Events

EventDescription
wds-open-changeCustomEvent<WdsCollapsibleOpenChangeDetail>The user or toggle() opened or closed the panel.

Methods

MethodDescription
toggle()Toggles the panel (like a click on the trigger). Does nothing when disabled.

Slots

SlotDescription
(default)Trigger, content and any other elements.

wds-collapsible-trigger#

Wraps the button that toggles the nearest wds-collapsible. It has no look of its own (display: contents). The first element inside (e.g. wds-button or button) gets aria-expanded, aria-controls and disabled, and the trigger itself data-state="open|closed".

Slots

SlotDescription
(default)The button.

wds-collapsible-content#

Content of the nearest wds-collapsible. It expands smoothly (height through grid-template-rows), and when closed it is visibility: hidden, so it also leaves the tab sequence and the accessibility tree. The state is in data-state="open|closed".

Slots

SlotDescription
(default)Content.

CSS parts (::part)

PartDescription
contentInner container that clips the content during the animation.

CSS custom properties

PropertyDescription
--wds-collapsible-durationAnimation duration (default 200ms).

Accessibility#

Screen reader#

wds-collapsible-trigger has no role of its own: the first element inside it (wds-button or <button>) is the button. It gets aria-expanded with the current state and aria-controls pointing to the content.

A closed wds-collapsible-content has visibility: hidden, so its content is hidden from screen readers and from the tab sequence.

With disabled the trigger button is disabled. Give an icon-only trigger button a label.

Keyboard support#

KeyFunction
TabMoves focus to the trigger, then into the open content.
EnterSpaceOpens or closes the panel.
Footer