Data display
ITree
A nested list that can be expanded and collapsed — a file browser, a category hierarchy, an org chart.
- src
- components
- Button.vue
- Input.vue
- index.ts
- docs
- README.md
Values, not objects
Both models are arrays of values: v-model holds what is selected, v-model:expanded holds what is open. A node's value identifies it, falling back to its label — so both models survive a round trip through a URL, a store or a request body.
const items = [
{ label: 'src', value: 'src-dir', children: srcChildren },
{ label: 'README.md' }, // value is "README.md"
]Multiple selection
multiple lets several nodes be selected. Add propagate-select and choosing a folder chooses everything beneath it.
- src
- components
- index.ts
- docs
- README.md
Selected: index.ts
Counts
A node's count sits against the row's trailing edge, so the numbers line up in a column rather than stepping inward with each level.
- src24
- components18
- composables6
- index.ts
- docs9
- archive0
A count of 0 still renders.
Indentation
Depth is padding on the row rather than a nested container, so hover and selection backgrounds span the full width at every level.
indent sets how many pixels each level adds, on top of a small fixed inset.
<ITree :items="files" :indent="24" />Props
| Prop | Type | Default | Description |
|---|---|---|---|
items | TreeItemOption[] | [] | |
modelValue | string[] | [] | Selected values; v-model |
expanded | string[] | [] | Open values; v-model:expanded |
multiple | boolean | false | |
propagateSelect | boolean | false | Selecting a parent selects its descendants; needs multiple |
size | 'sm' | 'md' | 'md' | |
indent | number | 16 | Pixels added per level |
disabled | boolean | false | |
ariaLabel | string | — | Names the tree |
unstyled | boolean | — | Skip built-in classes |
ui | { root?, item?, expander?, spacer?, icon?, label?, count? } | — | Per-slot class overrides |
TreeItemOption
| Field | Type | Description |
|---|---|---|
label | string | |
value | string | Defaults to the label |
icon | IconLike | |
disabled | boolean | |
count | number | Shown against the row's trailing edge; 0 still renders |
children | TreeItemOption[] | Makes the node expandable |
Events
| Event | Payload |
|---|---|
update:modelValue | string[] |
update:expanded | string[] |
Slots
| Slot | Props | Description |
|---|---|---|
item | { item, level, expanded } | Replaces a row's contents |
Accessibility
Arrow keys move across the whole tree whatever the nesting: up and down walk the visible rows, right opens a branch, left closes it, and typing jumps to a matching label. A leaf reserves the same space a chevron takes, so the labels stay in one column.
Give the tree a name with ariaLabel.