WlAccordion
Selection
Overview
Details
Unavailable section
Full example
<div class="wl-stack" data-space="md">
<WlAccordion
v-model:open-keys="open"
:items="[
{ key: 'overview', title: 'Overview', content: 'General guidelines.' },
{ key: 'details', title: 'Details', content: 'Agreements and examples.' },
{ key: 'locked', title: 'Unavailable section', disabled: true }
]"
/>
</div>Expansion modes and scoped slot
Controlled through openKeys, single, disabled, item slot and a separate uncontrolled accordion.
Setup
Import CSS explicitly and import components from legato-ui.
Scoped slot: open = true
Themes
Legato, Legato Dark, Classic and Classic Dark switch through tokens.
Scoped slot: open = false
Restricted section
This section is unavailable.
Scoped slot: open = false
Open keys: guide.
Uncontrolled variant
Setup
Themes
Restricted section
Full example
<script setup lang="ts">
import { WlAccordion, type WlAccordionItem, WlButton, WlCheckbox } from "legato-ui";
import { ref, watch } from "vue";
const single = ref(false);
const open = ref(["guide"]);
const action = ref("");
watch(single, (enabled) => {
if (enabled) open.value = open.value.slice(0, 1);
});
const items: WlAccordionItem[] = [{ key: "guide", title: "Setup", content: "Import CSS explicitly and import components from legato-ui." }, { key: "theme", title: "Themes", content: "Legato, Legato Dark, Classic and Classic Dark switch through tokens." }, { key: "later", title: "Restricted section", content: "This section is unavailable.", disabled: true }];
</script>
<template>
<div class="wl-stack" data-space="lg">
<WlCheckbox v-model="single">{{ "Only one expanded item" }}</WlCheckbox>
<WlAccordion v-model:open-keys="open" :items="items" :single="single">
<template #item="{ item, open: expanded }">
<div class="wl-stack" data-space="sm">
<p class="wl-text-body">{{ item.content }}</p>
<div>
<WlButton size="sm" @click="action = item.title">{{ "Check" }} {{ item.title }}</WlButton>
</div>
<p class="wl-text-small wl-text-muted">{{ "Scoped slot: open =" }} {{ expanded }}</p>
</div>
</template>
</WlAccordion>
<p class="wl-text-small" role="status">
{{ "Open keys:" }} {{ open.join(', ') || "none" }}.
{{ action ? "Action: " + action : '' }}
</p>
<div class="wl-stack" data-space="sm">
<h3 class="wl-text-label">{{ "Uncontrolled variant" }}</h3>
<WlAccordion single :items="items" />
</div>
</div>
</template>Props
Types, accepted values and literal defaults come from the public manifest. Inherited settings name their source; “Not set” means no default is declared.
| Prop | Type / values | Default | Purpose |
|---|---|---|---|
items | readonly Item[] | [] | WlAccordionItem[]: { key, title, content?, disabled? }. |
single | boolean | false | Only one item is open. |
openKeys | readonly Item["key"][] | Not set | Open section keys; controlled through v-model:openKeys. |
defaultOpenKeys | readonly Item["key"][] | Not set | Initially expanded item keys for an uncontrolled accordion. |
pt | WlPt< | Not set | Attributes and callbacks for the component's documented pass-through sections. |
Events
| Event | Payload | When emitted |
|---|---|---|
update:openKeys | [value: Item["key"][]] | New list of open keys. |
Slots
| Slot | Type / values | Content |
|---|---|---|
item | item?(props: { item: Item; open: boolean }): unknown; | Item body instead of item.content; scope: { item, open }. |
header | header?(props: { item: Item; open: boolean }): unknown; | Custom item heading with its current open state. |
icon | icon?(props: { item: Item; open: boolean }): unknown; | Custom disclosure icon with its current open state. |
Pass-through: pt
Sections WlAccordion are listed below. Attributes merge in this order: createWlPt() WlConfig.ptpt instance. Class and style merge; the last supplied value takes priority for other attributes.
| Section | DOM | Purpose |
|---|---|---|
root | div.wl-acc | Main element of the component. |
item | details.wl-acc__item | One repeated item. |
header | summary.wl-acc__summary | Component heading area. |
content | div.wl-acc__body | Main content area. |
Sections refer to the component DOM. Dotted names identify a configuration group and its section; composite parts use their own pt groups. Global and local attributes merge, with class and style added together.
Keyboard and accessibility
- Card, Accordion, Alert and Segmented expose component font-size, line-height, font-weight and font-family tokens. Defaults retain 1.0 typography. Import styles/primitives.css and add wl-type-scale to opt into semantic roles; the mapping table and live toggle are in Typography → Scale. Set local scale values on the same group, or override a component token on a closer element. Select and MultiSelect use the font size of each role. To scale a local dropdown, pass the class and role values through pt.overlay.
- Native details/summary provide keyboard expansion; a disabled item receives aria-disabled and does not change openKeys.
- In controlled mode, update openKeys through update:openKeys. Single limits expansion when toggling an item.
- Place buttons and links in the item slot body, keeping clear summary labels and focus order.
Keyboard and application responsibilities
| Key | Action |
|---|---|
| Tab / Shift+Tab | Move between enabled links, actions and form controls. |
| Enter / Space | Activate native actions; links follow with Enter. |
Provide a meaningful accessible name and connect labels, hints and errors to the focusable element. Check the behavior with your own data and a screen reader.
WAI-ARIA Authoring PracticesIn your application, check keyboard controls, zoom and focus visibility. State labels and required information must be readable in every theme.