layoutcontroller
z-accordionAccordion
Collapsible content panels with single or multiple open items, animated height transitions, and keyboard navigation.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
multiple | boolean | false | Allows several panels to stay open at once; otherwise opening one closes the others. |
no-collapsible | boolean | false | Keeps at least one panel open: the last open panel cannot be closed, and the first enabled panel opens automatically. |
active | string | — | Open panels as a comma- or space-separated list of indices, values, or ids; -1 closes all. Kept in sync with the open state. |
duration | number | 150 | Panel transition duration in milliseconds; 0 disables animation. |
no-animation | boolean | false | Skips panel transitions entirely, showing and hiding content instantly. |
targets | string | '' | CSS selector for item elements within the container, replacing the default item detection. |
trigger | string | '' | CSS selector for the clickable trigger within each item, replacing .z-accordion-title detection. |
content | string | '' | CSS selector for the collapsible panel within each item, replacing .z-accordion-content detection. |
Inherited from Base
| Attribute | Type | Default | Description |
|---|---|---|---|
cls | string | '' | Adds classes to named parts as key: classes pairs; a plain string targets the default part. |
stl | string | '' | 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
| Key | Default class | cls | stl | Description |
|---|---|---|---|---|
open | z-open | yes | no | Class applied to open items; the default cls target for this component. |
CSS Variables
| Variable | Default | Scope | Description |
|---|---|---|---|
--z-accordion-border | var(--z-border) | .z-accordion | Border color of the accordion items. |
--z-accordion-border-o | var(--z-border-o) | .z-accordion | Opacity applied to the item border color. |
--z-accordion-border-style · hook | solid | .z-accordion > li, .z-accordion > div | Border style of each item. |
--z-accordion-border-w · hook | 0 0 1px 0 | .z-accordion > li, .z-accordion > div | Border widths per side of each item; the default draws only a bottom hairline. |
--z-accordion-transition | 150ms cubic-bezier(0.16, 1, 0.3, 1) | .z-accordion | Transition timing used for the accordion's animated state changes. |
--z-disabled-opacity · hook | 0.5 | .z-accordion > .z-disabled > .z-accordion-title, .z-accordion-title.z-disabled, .z-accordion-title:disabled | Opacity of disabled triggers. |
Events
| Event | Detail | Flags | Description |
|---|---|---|---|
z-accordion:before-hide | { index: number; item: HTMLElement; trigger: HTMLElement; content: HTMLElement; value: string } | cancelable, bubbles | Fires before a panel closes; preventDefault() cancels the change. |
z-accordion:before-show | { index: number; item: HTMLElement; trigger: HTMLElement; content: HTMLElement; value: string } | cancelable, bubbles | Fires 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 } | bubbles | Fires 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 } | bubbles | Fires after a panel's close transition completes. |
z-accordion:hide | { index: number; item: HTMLElement; trigger: HTMLElement; content: HTMLElement; value: string } | bubbles | Fires when a panel starts closing. |
z-accordion:mount · from Controller | Record<string, unknown> | bubbles | Fires when deferred template content is mounted into the container. |
z-accordion:show | { index: number; item: HTMLElement; trigger: HTMLElement; content: HTMLElement; value: string } | bubbles | Fires when a panel starts opening. |
z-accordion:shown | { index: number; item: HTMLElement; trigger: HTMLElement; content: HTMLElement; value: string } | bubbles | Fires after a panel's open transition completes. |
Methods
| Signature | Description |
|---|---|
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(): void | Re-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
| Attribute | Values | Applies to | Role | Description |
|---|---|---|---|---|
data-accordion-ignore | — | descendant | config | Excludes the element from item detection. |
data-accordion-item | close-all, next, open-all, previous | descendant | trigger | Turns the element into an accordion control: open-all, close-all, next, previous, or a target index, value, or id to toggle. |
data-fn · from Controller | template | descendant | config | Marks a deferred <template> child whose content is mounted into the container on demand. |
data-part | list | descendant | marker | Marks the list container (list) when the host itself is not the accordion list. |
data-value | — | descendant | read-only | Identifies the item for active and toggle targets; falls back to the item id or index. |
CSS Classes
| Class | Role | Applies to | Description |
|---|---|---|---|
.z-accordion | root | z-accordion | Root list container. |
.z-accordion-content | element | .z-accordion | Collapsible panel associated with a trigger. |
.z-accordion-icon | element | .z-accordion | Indicator icon in the trigger, styled to reflect the open state. |
.z-accordion-title | element | .z-accordion | Clickable trigger that toggles its panel. |
.z-open | state | .z-accordion | State class on open items. |
Keyboard
| Keys | Action | When |
|---|---|---|
| ArrowDown ArrowUp | Move focus to the next / previous enabled trigger, wrapping at the ends. | Focus is on a trigger |
| Home End | Move 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 | |
| Enter | Toggle 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-expandedandaria-controls; panels receiverole="region"andaria-labelledbyunless they are lists or already carry a role. - With
no-collapsible, the last open trigger is markedaria-disabledbecause it cannot be closed.