WlTree
States
Arrow keys move focus and open branches. Home and End jump to the first and last available nodes. Enter or Space chooses the focused node.
Full example
<div class="wl-stack" data-space="sm">
<WlTree
v-model="selected"
v-model:expanded-keys="expanded"
:nodes="nodes"
label="Project folders"
/>
<output v-if="selected !== null" aria-label="Selected:"><code>{{ selected }}</code></output>
</div>Content
Full example
<div class="wl-stack" data-space="sm">
<WlTree
v-model="selected"
v-model:expanded-keys="expanded"
:nodes="nodes"
label="Project folders"
/>
<output v-if="selected !== null" aria-label="Selected:"><code>{{ selected }}</code></output>
</div>Example data
Full example
<div class="wl-stack" data-space="sm">
<WlTree
v-model="selected"
v-model:expanded-keys="expanded"
:nodes="nodes"
label="Project folders"
/>
<output v-if="selected !== null" aria-label="Selected:"><code>{{ selected }}</code></output>
</div>Controlled folder expansion
Expand every folder, select the guide, and collapse the branches. The selected key stays available while its row is hidden.
Full example
<script setup lang="ts">
import { WlButton, WlTree, type WlTreeKey, type WlTreeNode } from "legato-ui";
import { computed, ref } from "vue";
const selected = ref<WlTreeKey | null>(null);
const expanded = ref<readonly WlTreeKey[]>(["materials"]);
const nodes = computed<readonly WlTreeNode[]>(() => [
{ key: "materials", label: "Materials", children: [
{ key: "design", label: "Design", children: [
{ key: "guide", label: "Team guide" }
] },
{ key: "brief", label: "Brief" }
] },
{ key: "archive", label: "Archive", disabled: true }
]);
</script>
<template>
<div class="wl-stack" data-space="sm">
<div class="wl-inline" data-space="sm">
<WlButton size="sm" @click="expanded = ['materials', 'design']">{{ "Expand all folders" }}</WlButton>
<WlButton size="sm" @click="expanded = []">{{ "Collapse all folders" }}</WlButton>
</div>
<WlTree
v-model="selected"
v-model:expanded-keys="expanded"
:nodes="nodes"
label="Project folders"
>
<template #node="{ node }">
<span>{{ node.label }}</span>
<span v-if="node.disabled" class="wl-text-small wl-text-muted"> · {{ "Unavailable" }}</span>
</template>
</WlTree>
<output v-if="selected !== null" aria-label="Selected:"><code>{{ selected }}</code></output>
</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.
v-model: WlTreeKey |Selected node key, or null when no node is selected.
| Prop | Type / values | Default | Purpose |
|---|---|---|---|
nodes * | readonly WlTreeNode[] | Required | Nested nodes with unique keys. |
label | string | Not set | Accessible label for the tree. |
disabled | boolean | Not set | Prevent focus and selection of all nodes. |
pt | WlPt< | Not set | Attributes of the tree and its rendered rows. |
Events
| Event | Payload | When emitted |
|---|---|---|
select | [node: WlTreeNode] | An enabled node was activated, even when already selected. |
update:modelValue | WlTreeKey | | The key selected by activating a node. |
update:expandedKeys | readonly WlTreeKey[] | The updated keys of expanded branches. |
Slots
| Slot | Type / values | Content |
|---|---|---|
node | node?(props: WlTreeNodeSlotProps): unknown; | Row label or other non-interactive content. |
empty | empty?(): unknown; | Content when the tree has no nodes. |
Pass-through: pt
Sections WlTree 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-tree | Main element of the component. |
item | div.wl-tree__item | One repeated item. |
indent | span.wl-tree__indent | Depth indentation of a row. |
expander | span.wl-tree__expander | Visual branch toggle in a row. |
label | span.wl-tree__label | Displayed text label. |
empty | div.wl-tree__empty | Content shown when there are no items. |
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
- Arrow keys move focus and open branches. Home and End jump to the first and last available nodes. Enter or Space chooses the focused node.
- Give the tree a name that describes the collection, such as Project folders.
- Keep row slot content non-interactive so a node is the only focus target on that row.
Keyboard and application responsibilities
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 PracticesChanges are emitted through v-model. After selection, cancellation and reset, labels and states must remain clear.
In your application, check keyboard controls, zoom and focus visibility. State labels and required information must be readable in every theme.