Skip to content

Collapsible

A disclosure primitive with ARIA wiring, disabled state, find-in-page support, and programmatic control.

<pe-collapsible class="Collapsible">
<button type="button" class="Trigger" data-collapsible-trigger>
  Project details
</button>
<div class="Panel" data-collapsible-panel>
  <p class="Content">Plain Elements provides accessible, unstyled UI primitives.</p>
</div>
</pe-collapsible>

Use Collapsible for one independent disclosure region and Accordion for a related group. Use a native button trigger. Add data-collapsible-hidden-until-found when closed content must remain available to browser find-in-page.

Part Selector Role
Host <pe-collapsible> Lifecycle and open-state boundary
Trigger [data-collapsible-trigger] Toggles the panel and receives aria-expanded / aria-controls
Panel [data-collapsible-panel] Receives a generated ID, hidden state, and size CSS variables

Host, trigger, and panel expose data-state="open|closed". Disabled parts expose data-disabled.

NameDescription
data-collapsible-openBoolean host attribute reflecting the current open state. It can also be changed externally.
data-collapsible-disabledOn the host or a trigger: ignores user interaction while retaining focusability.
data-collapsible-hidden-until-foundOn the host or panel: uses hidden="until-found" while closed and opens on beforematch.
NameTypeDescription
isOpenboolean (readonly)Reads the current open state. Set state with open(), close(), or toggle().
disabledbooleanGets or sets root disabled state.
open(trigger?) / close(trigger?) / toggle(trigger?)voidChanges state programmatically and optionally records the initiating trigger.

The panel exposes --collapsible-panel-height and --collapsible-panel-width while enter and exit transitions run. After the open animation finishes, both return to auto so panel content can grow naturally. The component adds data-starting-style while animating in and data-ending-style while animating out. It waits for finite animations on the panel before applying hidden.

.Collapsible.Animated .Panel {
height: var(--collapsible-panel-height);
overflow: hidden;
transition: height 150ms ease-out;
}
.Collapsible.Animated .Panel[hidden]:not([hidden="until-found"]) {
display: none;
}
.Collapsible.Animated .Panel[data-starting-style],
.Collapsible.Animated .Panel[data-ending-style] {
height: 0;
}

Closed panels are hidden after finite exit animations finish. beforematch skips the opening animation so the browser can scroll immediately.

NameDescription
pe-collapsible:openBubbles and is composed. Fired when the panel opens.
pe-collapsible:closeBubbles and is composed. Fired when the panel closes.

Event detail fields: open, panel, optional trigger, and reason (trigger, programmatic, attribute, or beforematch).