WlAccordion
Accordion using details/summary: controlled through openKeys or uncontrolled.
Change props to see the result: the example and code use the same settings. “Reset” restores the initial values.
Settings
Only one item is open.
Props items, openKeys, defaultOpenKeys, pt, models, handlers and slots can be edited in the SFC. See their descriptions in API.
Example
Overview
General guidelines.
Details
Agreements and examples.
Unavailable section
Focus: outside the example · pointer: outside the example
Explore the live example and copy its Vue SFC into your application. Settings on the left can be combined.
Code for your application
Vue SFC · current settings
<script setup lang="ts">
import { WlAccordion } from "legato-ui";
import { ref } from "vue";
const open = ref<string[]>(["overview"]);
</script>
<template>
<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>
</template>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, Gavia, Gavia Dark, Classic, Classic Dark and Newspaper switch through tokens.
Scoped slot: open = false
Restricted section
This section is unavailable.
Scoped slot: open = false
Open keys: guide.
Uncontrolled variant
Setup
Import CSS explicitly and import components from legato-ui.
Themes
Legato, Legato Dark, Gavia, Gavia Dark, Classic, Classic Dark and Newspaper switch through tokens.
Restricted section
This section is unavailable.
Vue SFC · additional 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, Gavia, Gavia Dark, Classic, Classic Dark and Newspaper 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>