Skip to content

Tree

experimental

The Tree component presents a hierarchical list. Any item in the hierarchy may have child items, and items that have children may be expanded or collapsed to show or hide the children. Items with children can be cexpanded or collapsed and child items can be selected. The component uses the ARIA tree role and implements the W3C ARIA APG Tree View Pattern. Combine it with the Field component to access all functionalities.

Examples

Base

The component allows the user to select one or more items from a hierarchically organized collection. For example, a file system navigator that uses a tree view, each item displays a folder or file. Folder items can be expanded to reveal the contents of the folder, which may be files, folders, or both.

Accessibility Note:

A tree view is primarily navigated with arrow keys on the keyboard instead of the tab key. This form of navigation is more similar to native applications than to web applications. For this reason, consider alternative options to address the functionality you need before using a tree component. A tree component is at the most times not needed for typical site navigation that is styled to look like a tree with expandable sections.

Options

Instead of using the <o-tree-item> component directly inside the default slot, an options prop can be set, which can be used to define the options programmatically. It accepts several different formats of values:

  • An array of primitives ['A', 'B', 'C']
  • An object literal with key-value pairs { a: 'A', b: 'B', c: 'C' }
  • An array of objects with label and value properties
  • Grouped options by adding additional options to the option object.

Note

The options prop works the same as the Select input component options prop.

Selection

When setting the selectable property, users can select any item. The current selected item value is available in the modelValue property. In "multi-select" trees users are able to select more than one item.

Single

When a single-select tree receives focus, if none of the tree items are selected before the tree receives focus, focus is set on the first node. If a tree item is selected before the tree receives focus, focus is set on the selected tree item.

Multiple

You can enable multi-select with the multiple property. In multi-select trees, the selected state is always independent of the focus. For example, in a typical file system navigator, the user can move focus to select any number of files for an action, such as copy or move. The visual design should make it clear which items are selected and which item has focus. When a multi-select tree receives focus, if none of the tree items are selected before the tree receives focus, focus is set on the first tree item. If one or more tree items are selected before the tree receives focus, focus is set on the first selected node.

Scrollable

When having to many options, consider adding a max height using the scrollHeight property, which allows to cap the tree at a fixed max-height. This will render a long tree of options with a scrollbar. The component will emit a scroll-start or scroll-end event, when the top or bottom of the tree is reached.

Slot

The item label can be customised using the label slot.

Tree Component

A simple tree view, for any type of hierarchical list.

html
<o-tree></o-tree>

Props

Prop nameDescriptionTypeValuesDefault
animationCustom animation (transition name)string-
From config:
tree: {
  animation: "slide"
}
ariaLabelDefines a string value that labels an interactive element.string-
ariaLabelledbyIdentifier of the underlying input element.string-
checkableEnable a checkbox on the item elementboolean-false
collapsableIf sub tree items are shown as a accordionboolean-true
disabledTree will be disabledboolean-false
emptyLabelA label which is displayed when no options are visiblestring-
From config:
tree: {
  emptyLabel: undefined
}
iconPackIcon pack to usestringmdi, fa, fas and any other custom icon pack
From config:
tree: {
  iconPack: undefined
}
iconSizeIcon sizestringsmall, medium, large
From config:
tree: {
  iconSize: undefined
}
idSame as native id. Also set the for label for o-field wrapper - default is an uuid.string-useId()
v-modelThe selected item value, use v-model to make it two-way bindingunknown-
multipleAllows multiple selections - converts the modelValue into an arrayboolean-
optionsTree items, unnecessary when default slot is usedOptionsPropWithGroups<unknown>-
overrideOverride existing theme classes completelyboolean-
scrollHeightHeight of the tree, a scrollbar is defined if height of list exceeds this valuenumber | string-
From config:
tree: {
  scrollHeight: undefined
}
selectableEnables item selectionboolean-false
toggleIconThe chevron icon to for the toggle element before each itemstring-
From config:
tree: {
  toggleIcon: undefined
}

Events

Event namePropertiesDescription
update:model-valuevalue unknown - updated modelValue propmodelValue prop two-way binding
selectvalue unknown - selected valueon select event - fired before update:modelValue
focusevent Event - native eventon tree focus event
blurevent Event - native eventon tree blur event
scroll-startscrolling inside the tree reached the start
scroll-endscrolling inside the tree reached the end

Slots

NameDescriptionBindings
headerDefine an additional header
defaultDefine the tree items here
emptyDefine the content to show if the list is empty
footerDefine an additional footer

TreeItem Component

A tree list item.

html
<o-tree-item></o-tree-item>

Props

Prop nameDescriptionTypeValuesDefault
animationTransition name to apply on tree liststring-
From config:
tree: {
  animation: "slide"
}
ariaLabelDefines a string value that labels an interactive element.string-
ariaLabelledbyIdentifier of the underlying input element.string-
disabledTree item will be disabledboolean-false
expandedTree item will be expandedboolean-false
hiddenDefine whether the item is visible or notboolean-false
iconIcon to be shownstring-
iconPackIcon pack to usestringmdi, fa, fas and any other custom icon pack
From config:
tree: {
  iconPack: undefined
}
iconSizeIcon sizestringsmall, medium, large
From config:
tree: {
  iconSize: undefined
}
labelTree item labelstring-
optionsSubtree items, unnecessary when default slot is usedOptionsProp<unknown>-
overrideOverride existing theme classes completelyboolean-
subtreeIdHTML element Id of the sub tree ol list elementstring-useId()
valueItem value (it will be used as the v-model of the wrapper component) - default is an uuidunknown-useId()

Events

Event namePropertiesDescription
clickvalue unknown - value prop data
event event - native event
onclick event
openon sub tree opened
closeon sub tree closed

Slots

NameDescriptionBindings
labelOverride the label, default is label propexpanded boolean - item is expanded
selected boolean - item is selected
disabled boolean - item is disabled
defaultDefine subtree items here

Class Inspector

Classes applied to the element:
Want to know how does the Class Inspector work?
Class propDescriptionPropsSuffixes
rootClass
Class of the root element.
disabledClass
Clas of the root element when disabled.
disabled
selectableClass
Class of the root element when selectable.
selectable
multipleClass
Class of the root element when multiple.
multiple
headerClass
Class of the header slot wrapper element.
footerClass
Class of the footer slot wrapper element.
emptyClass
Class of the empty slot wrapper element.
listClass
Class of the tree list element.
itemClass
Class of the tree item root element.
itemSelectedClass
Class of the tree item root element when selected.
itemFocusedClass
Class of the tree item root element when focused.
itemClickableClass
Class of the tree item root element when clickable.
itemDisabledClass
Class of the tree item root element when disabled.
disabled
itemLabelClass
Class of the tree item label element element.
itemSubtreeClass
Class of the tree item subtree element.

Sass Variables

Current theme ➜ Oruga

The theme does not have any custom variables for this component.

Current theme ➜ Bulma

The theme does not have any custom variables for this component.

Current theme ➜ Bootstrap

The theme does not have any custom variables for this component.

Released under the MIT License.