Skip to content

Tree

YhTree displays hierarchical data and supports checkbox linkage, lazy loading, filtering, drag-and-drop, and virtual scrolling.

Basic Usage

Guides
Components
Basic Usage

Checkbox and Disabled Nodes

Enable show-checkbox to select multiple nodes. Disabled nodes remain visible but do not respond to click or checkbox interactions.

Team A
Member A-1
Member A-2
Team B
Checkbox and Disabled Nodes

Lazy Loading

Enable lazy and provide load to fetch child nodes on demand when a branch expands.

Async Root
Lazy Loading

Filtering

Use the exposed filter method with the built-in label matching logic, or combine it with filter-method for custom filtering behavior.

Team A
Team B
Filtering

Virtual Scrolling

Enable virtual for large datasets, then control the rendering window with height and item-height.

Virtual Node 0
Virtual Node 1
Virtual Node 2
Virtual Node 3
Virtual Node 4
Virtual Node 5
Virtual Node 6
Virtual Node 7
Virtual Node 8
Virtual Node 9
Virtual Node 10
Virtual Node 11
Virtual Scrolling

Custom Rendering and Drag-and-Drop

YhTree exposes default, icon, prefix, suffix, and empty slots, and also supports draggable with the full drag lifecycle events. Use these capabilities when you need custom node layouts, action areas, or business-side sorting interactions.

Use in Nuxt

After enabling the YH-UI Nuxt module, YhTree can be used directly in pages and components. Tree data, default expanded state, and empty state can render during SSR, while DOM-dependent features such as virtual scrolling and drag-and-drop continue on the client after hydration.

Guides
Installation
Theme
Components
Use in Nuxt

API

Props

NameDescriptionTypeDefault
dataTree data sourceTreeNodeData[][]
propsMapping config for label, children, and disabled fields{ label?: string; children?: string; disabled?: string }{ label: 'label', children: 'children', disabled: 'disabled' }
node-keyField name used to read the node key from raw datastring'id'
show-checkboxWhether checkboxes are displayedbooleanfalse
checkbox-positionCheckbox position relative to the label'left' | 'right''left'
default-expand-allWhether all nodes are expanded initiallybooleanfalse
default-expanded-keysNode keys expanded by default(string | number)[][]
default-checked-keysNode keys checked by default(string | number)[][]
current-node-keyCurrent highlighted node key, usable with v-model:current-node-keystring | number | undefinedundefined
highlight-currentWhether the current node is highlightedbooleantrue
accordionWhether only one sibling branch can remain expandedbooleanfalse
indentHorizontal indentation in pixels for each levelnumber18
check-strictlyWhether parent and child checked states are decoupledbooleanfalse
expand-on-click-nodeWhether clicking a node toggles expansionbooleantrue
check-on-click-nodeWhether clicking node content toggles checked state when checkboxes are enabledbooleanfalse
empty-textEmpty-state text; falls back to locale tree.emptyText when emptystring''
filter-methodCustom filter function(query: string, node: TreeNode) => booleanundefined
loadLazy load function for child nodes(node: TreeNode) => Promise<TreeNodeData[]>undefined
lazyWhether lazy loading is enabledbooleanfalse
draggableWhether drag-and-drop is enabledbooleanfalse
show-lineWhether connector lines are shownbooleanfalse
virtualWhether virtual scrolling is enabledbooleanfalse
heightVirtual list container heightnumber400
item-heightHeight of each node row in virtual modenumber30
theme-overridesComponent-level theme variable overridesTreeThemeVarsundefined

Events

NameDescriptionParameters
node-clickTriggered when a node is clicked(node: TreeNode, event: MouseEvent)
node-expandTriggered when a node expands or collapses(node: TreeNode, expanded: boolean)
checkTriggered when checked state changes(node: TreeNode, checked: boolean, checkedKeys: (string | number)[])
current-changeTriggered when a node is clicked and becomes current. Updating current-node-key from the outside or via setCurrentKey does not emit it(node: TreeNode | null)
node-drag-startTriggered when dragging starts(node: TreeNode, event: DragEvent)
node-drag-endDeclared drag-end event. The current implementation resets drag state but does not emit this event(node: TreeNode, dropNode: TreeNode | null, position: 'before' | 'after' | 'inner', event: DragEvent)
node-drag-overTriggered while dragging over a node(node: TreeNode, event: DragEvent)
node-drag-enterTriggered when a dragged node enters another node(node: TreeNode, event: DragEvent)
node-drag-leaveTriggered when a dragged node leaves another node(node: TreeNode, event: DragEvent)
node-dropTriggered when dropping completes(draggingNode: TreeNode, dropNode: TreeNode, position: 'before' | 'after' | 'inner', event: DragEvent)
update:currentNodeKeyTriggered when the current node key changes(key: string | number | undefined)

Slots

NameDescriptionParameters
defaultCustom node body content{ node: TreeNode; data: TreeNodeData }
iconCustom expand icon content{ node: TreeNode; data: TreeNodeData }
prefixContent rendered before the node label{ node: TreeNode; data: TreeNodeData }
suffixContent rendered after the node label{ node: TreeNode; data: TreeNodeData }
emptyEmpty-state content-

Expose

NameDescriptionType
filterFilters visible nodes by query(query: string) => void
getNodeGets a node by key(key: string | number) => TreeNode | undefined
getCheckedNodesReturns checked nodes() => TreeNode[]
getCheckedKeysReturns checked node keys() => (string | number)[]
getHalfCheckedNodesReturns half-checked nodes() => TreeNode[]
getHalfCheckedKeysReturns half-checked node keys() => (string | number)[]
getCurrentKeyReturns the current node key() => string | number | undefined
getCurrentNodeReturns the current node instance() => TreeNode | undefined
setCheckedSets the checked state for a single node(key: string | number, checked: boolean, deep?: boolean) => void
setCheckedKeysSets checked node keys in batch(keys: (string | number)[]) => void
setCheckedNodesSets checked state based on raw node data(nodes: TreeNodeData[]) => void
setCurrentKeySets the current node key only. It does not emit current-change(key: string | number | undefined) => void
setExpandedKeysSets expanded node keys in batch(keys: (string | number)[]) => void
setDataReplaces the tree data source(data: TreeNodeData[]) => void
expandNodeExpands a node(key: string | number) => void
collapseNodeCollapses a node(key: string | number) => void
scrollToScrolls to a position in virtual mode(options: number | ScrollToOptions) => void
scrollToNodeScrolls to a specific node in virtual mode(key: string | number) => void
expandedKeysReactive expanded node setRef<Set<string | number>>
checkedKeysReactive checked node setRef<Set<string | number>>

Theme Variables

YhTree supports themeOverrides and consumes the following component-scoped CSS variables.

VariableDescriptionDefault
--yh-tree-node-heightNode row height28px
--yh-tree-text-colorTree text colorvar(--yh-text-color-primary, #1d1d1f)
--yh-tree-hover-bgHover background for a node rowvar(--yh-color-primary-light-9, #ecf5ff)
--yh-tree-current-bgBackground for the current nodevar(--yh-color-primary-light-8, #d9ecff)

Type Exports

NameDescription
YhTreePropsProps type for YhTree
YhTreeEmitsEmits type for YhTree
YhTreeNodeDataRaw tree node data type
YhTreeNodeNormalized node type exposed through events and slots
YhTreeNodeSlotDataSlot payload type for tree nodes
YhTreeInstancePublic tree instance type
YhTreeNodeInstancePublic tree-node instance type

Released under the MIT License.