Skip to content

TreeView ​

A tree: files, categories, org charts. Items expand, can be browsed with the keyboard and can be selected.

Usage ​

Basic usage ​

Selected: index

vue
<script setup>
import { ref } from 'vue'
import { DocumentIcon, FolderIcon } from '@heroicons/vue/24/outline'

const files = [
  { id: 'src', label: 'src', icon: FolderIcon, children: [
    { id: 'index', label: 'index.ts', icon: DocumentIcon }
  ] },
  { id: 'package', label: 'package.json', icon: DocumentIcon }
]
const expanded = ref(['src'])
const selected = ref(null)
</script>

<template>
  <SuTreeView v-model:expanded="expanded" v-model:selected="selected" :items="files" aria-label="Project files" />
</template>

With :selectable="false", no item is marked as selected: Enter expands, and the select event is used to navigate.

vue
<SuTreeView :items="sections" :selectable="false" aria-label="Table of contents" @select="(item) => router.push(item.id)" />

API ​

Props ​

PropTypeDefaultDescription
itemsTreeItem[][]Items
selectablebooleantrueAn item can be selected (aria-selected)
size'sm' | 'md' | 'lg''md'Size
ariaLabel / ariaLabelledBystring-Tree name (required)

TreeItem ​

PropertyTypeDescription
idstring | numberUnique identifier
labelstringLabel
childrenTreeItem[]Children
iconComponentIcon
disabledbooleanInactive item (focusable, not selectable)

v-model and events ​

NamePayloadDescription
v-model:expanded(string | number)[]Expanded items
v-model:selectedstring | number | nullSelected item
selectTreeItemItem activated (click, Enter, Space)

Accessibility ​

  • role="tree", treeitem and group; level (aria-level), position (aria-posinset / aria-setsize) and expanded state (aria-expanded) are announced.
  • Each item is named by its own label only (aria-labelledby), without its children's text.
  • A single tab stop: the focused item, otherwise the selected item, otherwise the first one.
  • Keyboard: ↑ / ↓ visible items, → expands then moves to the first child, ← collapses then moves to the parent (reversed in RTL), Home / End, typeahead, * expands siblings, Enter / Space selects.

Publié sous licence MIT.