Tree view
VTreeView shows a hierarchy the reader folds and unfolds, such as files or a site map. It follows the ARIA tree pattern: one tab stop, arrow keys to move, open and close, and typeahead.
Usage
- Documents
- Resume.pdf
- Taxes
- Pictures
- Music
- Notes.txt
Examples
Selection
selectionMode="single" selects one node by click, Enter or Space, and v-model holds its value. The chevron folds a branch without selecting it. A disabled node stays reachable by the keyboard.
- Europe
- Paris
- Berlin
- Madrid
- Asia
Selected: berlin
Checkboxes
selectionMode="multiple" gives each row a checkbox. Checking a branch checks its subtree, and a branch partly checked shows a dash. The model lists checked nodes in tree order, a branch included once everything under it is checked. Disabled nodes keep their state.
- Content
- Read
- Write
- Publish
- Billing
- Invoices
- Refunds
- Audit log
Selected: read, write
Links
A node with href is a link, and current marks the page being viewed. To hand navigation to a router, call preventDefault() on the event that activate receives.
Lazy loading
loadChildren fetches the children of a lazy node on its first expansion, and the tree keeps them. A failure closes the node and announces it; the next expansion retries.
- eu-west
- us-east
End content
The #end slot adds content at the end of each row, such as a count. Keep it free of focusable elements: a row is a single control.
- Inbox12
- Work9
- Family3
- Drafts
- Spam41
API
Props
| Prop | Type | Default |
|---|---|---|
items | TreeItem[] | none |
First level of the tree. Each node has a unique value and a label, and optional icon, children, lazy, href, current and disabled. | ||
selectionMode | TreeSelectionMode'none' | 'single' | 'multiple' | 'none' |
| Whether nodes can be selected: not at all, one at a time, or several with checkboxes. | ||
loadChildren | (item: TreeItem) => Promise<TreeItem[]> | none |
Fetches the children of a lazy node on its first expansion. A failure collapses the node; the next expansion retries. | ||
size | TreeViewSize'sm' | 'md' | 'md' |
| Row height. | ||
label | string | none |
| Accessible name of the tree. Defaults to the library dictionary. | ||
v-model | TreeViewModelValue | null |
Selection: a value or null in single mode, an array in multiple mode. A value given for a branch checks its subtree. | ||
v-model:expanded | ItemValue[] | [] |
| Values of the expanded nodes. Unbound, the tree keeps this state itself. | ||
Events
| Event | Type |
|---|---|
activate | [item: TreeItem, event: MouseEvent | KeyboardEvent] |
A node was clicked or Enter was pressed on it. Receives the node and the event; preventDefault() cancels a link. | |
Slots
| Slot | Type |
|---|---|
icon | TreeItemSlotProps |
Content replacing the icon. Receives item, level and expanded. | |
label | TreeItemSlotProps |
| Content replacing the label. Receives the same props. | |
end | TreeItemSlotProps |
| Content at the end of the row. Must not be focusable. | |
Types
Types used in the API tables. Import exported types from vectis-ui.
export interface BuiltinIcon {
name: string
paths: readonly [string] | readonly [string, string]
}export type IconRender =
| { path: string; viewBox?: string }
| { component: Component; props?: Record<string, unknown> }
| { src: string }
| { text: string; class?: string }
| { class: string }export type IconSource = string | BuiltinIcon | IconRender
export type ItemValue = string | number
export interface TreeItem {
value: ItemValue
label: string
icon?: IconSource
children?: TreeItem[]
lazy?: boolean
href?: string
current?: boolean
disabled?: boolean
}export interface TreeItemSlotProps {
item: TreeItem
level: number
expanded: boolean
}export type TreeViewModelValue = ItemValue | ItemValue[] | null
CSS variables
| Token | Value |
|---|---|
--vectis-control-size-check | 1.25rem |
--vectis-control-size-check-mark | 0.875rem |