layoutcontrollerz-accordion

Accordion

Collapsible content panels with single or multiple open items, animated height transitions, and keyboard navigation.

Attributes

AttributeTypeDefaultDescription
multiplebooleanfalseAllows several panels to stay open at once; otherwise opening one closes the others.
no-collapsiblebooleanfalseKeeps at least one panel open: the last open panel cannot be closed, and the first enabled panel opens automatically.
activestring—Open panels as a comma- or space-separated list of indices, values, or ids; -1 closes all. Kept in sync with the open state.
durationnumber150Panel transition duration in milliseconds; 0 disables animation.
no-animationbooleanfalseSkips panel transitions entirely, showing and hiding content instantly.
targetsstring''CSS selector for item elements within the container, replacing the default item detection.
triggerstring''CSS selector for the clickable trigger within each item, replacing .z-accordion-title detection.
contentstring''CSS selector for the collapsible panel within each item, replacing .z-accordion-content detection.
Inherited from Base
AttributeTypeDefaultDescription
clsstring''Adds classes to named parts as key: classes pairs; a plain string targets the default part.
stlstring''Adds inline styles to named parts as key: styles pairs; a plain string targets the default part.

Custom Styling (cls / stl)

Default cls target:open · defaultstl target:host-inner

KeyDefault classclsstlDescription
openz-openyesnoClass applied to open items; the default cls target for this component.

CSS Variables

VariableDefaultScopeDescription
--z-accordion-bordervar(--z-border).z-accordionBorder color of the accordion items.
--z-accordion-border-ovar(--z-border-o).z-accordionOpacity applied to the item border color.
--z-accordion-border-style · hooksolid.z-accordion > li, .z-accordion > divBorder style of each item.
--z-accordion-border-w · hook0 0 1px 0.z-accordion > li, .z-accordion > divBorder widths per side of each item; the default draws only a bottom hairline.
--z-accordion-transition150ms cubic-bezier(0.16, 1, 0.3, 1).z-accordionTransition timing used for the accordion's animated state changes.
--z-disabled-opacity · hook0.5.z-accordion > .z-disabled > .z-accordion-title, .z-accordion-title.z-disabled, .z-accordion-title:disabledOpacity of disabled triggers.

Events

EventDetailFlagsDescription
z-accordion:before-hide{ index: number; item: HTMLElement; trigger: HTMLElement; content: HTMLElement; value: string }cancelable, bubblesFires before a panel closes; preventDefault() cancels the change.
z-accordion:before-show{ index: number; item: HTMLElement; trigger: HTMLElement; content: HTMLElement; value: string }cancelable, bubblesFires before a panel opens; preventDefault() cancels the change.
z-accordion:change{ activeIndices: number[]; index: number; open: boolean; item: HTMLElement | null; trigger: HTMLElement | null; content: HTMLElement | null; value: string | null }bubblesFires after any open-state change; detail carries the active indices and the primarily affected item.
z-accordion:hidden{ index: number; item: HTMLElement; trigger: HTMLElement; content: HTMLElement; value: string }bubblesFires after a panel's close transition completes.
z-accordion:hide{ index: number; item: HTMLElement; trigger: HTMLElement; content: HTMLElement; value: string }bubblesFires when a panel starts closing.
z-accordion:mount · from ControllerRecord<string, unknown>bubblesFires when deferred template content is mounted into the container.
z-accordion:show{ index: number; item: HTMLElement; trigger: HTMLElement; content: HTMLElement; value: string }bubblesFires when a panel starts opening.
z-accordion:shown{ index: number; item: HTMLElement; trigger: HTMLElement; content: HTMLElement; value: string }bubblesFires after a panel's open transition completes.

Methods

SignatureDescription
activeIndices(): number[]Returns the indices of open panels, sorted ascending.
close(target: number | string, animate?: boolean = true): Promise<boolean>Closes the given panel; refuses to close the last one when no-collapsible is set.
closeAll(animate?: boolean = true): Promise<boolean>Closes all panels, keeping one open when no-collapsible is set.
open(target: number | string, animate?: boolean = true): Promise<boolean>Opens the panel at the given index, value, or id; resolves true when open.
openAll(animate?: boolean = true): Promise<boolean>Opens every enabled panel; with multiple off, opens only the first enabled one.
refresh(): voidRe-scans the DOM and rebinds listeners after items change.
toggle(target: number | string, animate?: boolean = true): Promise<boolean>Opens the given panel if closed, otherwise closes it.

Data Hooks

AttributeValuesApplies toRoleDescription
data-accordion-ignore—descendantconfigExcludes the element from item detection.
data-accordion-itemclose-all, next, open-all, previousdescendanttriggerTurns the element into an accordion control: open-all, close-all, next, previous, or a target index, value, or id to toggle.
data-fn · from ControllertemplatedescendantconfigMarks a deferred <template> child whose content is mounted into the container on demand.
data-partlistdescendantmarkerMarks the list container (list) when the host itself is not the accordion list.
data-value—descendantread-onlyIdentifies the item for active and toggle targets; falls back to the item id or index.

CSS Classes

ClassRoleApplies toDescription
.z-accordionrootz-accordionRoot list container.
.z-accordion-contentelement.z-accordionCollapsible panel associated with a trigger.
.z-accordion-iconelement.z-accordionIndicator icon in the trigger, styled to reflect the open state.
.z-accordion-titleelement.z-accordionClickable trigger that toggles its panel.
.z-openstate.z-accordionState class on open items.

Keyboard

KeysActionWhen
ArrowDown ArrowUpMove focus to the next / previous enabled trigger, wrapping at the ends.Focus is on a trigger
Home EndMove focus to the first / last enabled trigger.Focus is on a trigger
Toggle the focused panel when the trigger is not a native button.Focus is on a non-button trigger
EnterToggle the focused panel when the trigger is neither a button nor a link.Focus is on a non-button, non-link trigger

Accessibility

  • Triggers receive aria-expanded and aria-controls; panels receive role="region" and aria-labelledby unless they are lists or already carry a role.
  • With no-collapsible, the last open trigger is marked aria-disabled because it cannot be closed.