Skip to content

Tree View

Browse an expandable hierarchy while keeping focus and selection distinct.

Usage

Expanded hierarchy

Browse a realistic project hierarchy while each folder keeps its own independent expansion state.

Project filesatlas / apps / dashboard
Atlas workspaceWorkspace
Applications2 apps
Dashboard2 files
Overview.vue4.2 KB
Settings.vue3.8 KB
Storefront18 files
Packages1 package
tokens.ts6.1 KB
README.md2.4 KB

Collapsed

Start with descendants hidden, then reveal them without changing the source data.

Project filesatlas / apps / dashboard
Atlas workspaceWorkspace
Applications2 apps
Dashboard2 files
Overview.vue4.2 KB
Settings.vue3.8 KB
Storefront18 files
Packages1 package
tokens.ts6.1 KB
README.md2.4 KB

Multiple selection

Choose several files for review without confusing selection with folder expansion.

Review filesChoose files to include in the review
3 files selectedSpace toggles selection
Atlas workspaceWorkspace
Applications2 apps
Dashboard2 files
Overview.vue4.2 KB
Settings.vue3.8 KB
Storefront18 files
Packages1 package
tokens.ts6.1 KB
README.md2.4 KB

Unavailable

Keep an unavailable tree item visible while excluding it from activation.

Project filesatlas / apps / dashboard
Atlas workspaceWorkspace
Applications2 apps
Dashboard2 files
Overview.vue4.2 KB
Settings.vue3.8 KB
Storefront18 files
Packages1 package
tokens.ts6.1 KB
README.md2.4 KB

Controlled

Let the parent own the current value and apply accepted changes back to the component.

Project filesatlas / apps / dashboard
Atlas workspaceWorkspace
Applications2 apps
Dashboard2 files
Overview.vue4.2 KB
Settings.vue3.8 KB
Storefront18 files
Packages1 package
tokens.ts6.1 KB
README.md2.4 KB

API

Vue package: @sectile/vue/tree-view

Components
  • TreeViewRoot
  • TreeViewGroup
  • TreeViewItem
  • TreeViewDisclosure

Props

TreeViewRootProps

as

Element or component rendered for this part.

asChild

Whether to merge this part into its single child instead of rendering a wrapper.

defaultExpandedValues

Initially expanded values for uncontrolled state.

defaultHighlightedValue

Initially highlighted value for uncontrolled state.

defaultValue

Initial value used when the component owns its state.

disabled

Whether interaction is unavailable.

disabledItems

Item values excluded from focus and selection.

expandedValues

Controlled values whose descendants are visible.

highlightedValue

Value currently highlighted for keyboard interaction.

label

Accessible name announced for the control.

modelValue

Current value when state is controlled by the parent.

nodes

Flat hierarchy used to build the tree.

policies

Behavior policies that customize validation, movement, or selection.

readonly

Whether the value can be inspected but not changed.

selectionMode

Whether selection contains one value or multiple values.

TreeViewPartProps

as

Element or component rendered for this part.

asChild

Whether to merge this part into its single child instead of rendering a wrapper.

TreeViewGroupProps

as

Element or component rendered for this part.

asChild

Whether to merge this part into its single child instead of rendering a wrapper.

for

Value or ID of the related part targeted by this component.

Slots

TreeViewRootSlotProps

disabled

Whether interaction is unavailable.

expandedValues

Values whose descendants are visible.

highlightedValue

Value currently highlighted for interaction.

readonly

Whether the value can be inspected but not changed.

value

Current value exposed by this contract.

TreeViewItemSlotProps

disabled

Whether interaction is unavailable.

expanded

Whether descendants are visible.

expandedValues

Values whose descendants are visible.

highlighted

Whether this item is highlighted for interaction.

highlightedValue

Value currently highlighted for interaction.

readonly

Whether the value can be inspected but not changed.

selected

Whether this item is selected.

selectedValues

Current selected values.

value

Current value exposed by this contract.

Events

TreeViewRoot

update:expandedValues

Emitted when the requested expanded values change.

update:highlightedValue

Emitted when the requested highlighted value changes.

update:modelValue

Emitted when the component requests a new controlled value.

Other types

TreeViewPolicies

NameTypeRequired
eligible(id: ID) => boolean

TreeViewEligiblePredicate

ts
type TreeViewEligiblePredicate<ID extends string = string> = NonNullable<TreeViewPolicies<ID>['eligible']>

TreeViewValueChangeHandler

ts
type TreeViewValueChangeHandler = (value: readonly string[]) => void

TreeViewExpandedValuesChangeHandler

ts
type TreeViewExpandedValuesChangeHandler = (value: readonly string[]) => void

TreeViewHighlightedValueChangeHandler

ts
type TreeViewHighlightedValueChangeHandler = (value: string | null) => void

TreeNodeInput

NameTypeRequired
idIDYes
parentIDID | nullYes

TreeViewSelectionMode

ts
type TreeViewSelectionMode = 'single' | 'multiple'

Parts

Shared scope: [data-scope="tree-view"]. Combine it with a part selector to keep styles local to this component.

PartSelectorRoleExtra attributes
root[data-part="root"]Defines the component boundary and owns its composed parts.
group[data-part="group"]Groups related child items.
item[data-part="item"]Represents one selectable or actionable item.
disclosure[data-part="disclosure"]Expands or collapses child content.

Keyboard interaction

KeyBehavior
Arrow Up / Arrow DownMove between visible tree items.
Arrow RightExpand a branch or move into its first child.
Arrow LeftCollapse a branch or move to its parent.
Enter / SpaceSelect or activate the current item.

Accessibility

Tree items expose level, expansion, selection, and disabled state with one roving tab stop.

See the corresponding WAI-ARIA pattern for the host accessibility contract.

Released under the MIT License.