Tree

A hierarchical list structure component.

Tree

When to use

Almost anything can be represented in a tree structure. Examples include directories, organization hierarchies, biological classifications, countries, etc. The Tree component is a way of representing the hierarchical relationship between these things. You can also expand, collapse, and select a treeNode within a Tree.


Basic

The most basic usage, tell you how to use checkable, selectable, disabled, defaultExpandKeys, and etc.

Controlled Tree

Controlled mode lets parent nodes reflect the status of child nodes more intelligently.

Draggable

Drag treeNode to insert after the other treeNode or insert into the other parent TreeNode.
0-0
0-0-0
0-0-0-0
0-0-0-1
0-0-0-2
0-0-1
0-0-2
0-1
0-2

Load data asynchronously

To load data asynchronously when click to expand a treeNode.

Searchable

Searchable Tree

Tree with line

Tree with connected line between nodes, turn on by showLine, customize the preseted icon by switcherIcon.
showLine:

showIcon:

showLeafIcon:

Customize Icon

You can customize icons for different nodes.

Customize collapse/expand icon

customize collapse/expand icon of tree node

Directory

Built-in directory tree. multiple support ctrl(Windows) / command(Mac) selection.

Virtual scroll

Use virtual list through height prop.

API

Tree props
PropertyDescriptionTypeDefault
autoExpandParent
Whether to automatically expand a parent treeNode
boolean
true
blockNode
Whether treeNode fill remaining horizontal space
boolean
false
checkable
Adds a Checkbox before the treeNodes
boolean
false
checkedKeys
(Controlled) Specifies the keys of the checked treeNodes (PS: When this specifies the key of a treeNode which is also a parent treeNode, all the children treeNodes of will be checked; and vice versa, when it specifies the key of a treeNode which is a child treeNode, its parent treeNode will also be checked. When checkable and checkStrictly is true, its object has checked and halfChecked property. Regardless of whether the child or parent treeNode is checked, they won't impact each other.
string[] | {checked: string[], halfChecked: string[]}
[]
checkStrictly
Check treeNode precisely; parent treeNode and children treeNodes are not associated
boolean
false
defaultCheckedKeys
Specifies the keys of the default checked treeNodes
string[]
[]
defaultExpandAll
Whether to expand all treeNodes by default
boolean
false
defaultExpandedKeys
Specify the keys of the default expanded treeNodes
string[]
[]
defaultExpandParent
auto expand parent treeNodes when init
bool
true
defaultSelectedKeys
Specifies the keys of the default selected treeNodes
string[]
[]
disabled
whether disabled the tree
bool
false
draggable
Specifies whether this Tree is draggable (IE > 8)
boolean
false
expandedKeys
(Controlled) Specifies the keys of the expanded treeNodes
string[]
[]
filterTreeNode
Defines a function to filter (highlight) treeNodes. When the function returns true, the corresponding treeNode will be highlighted
function(node)
-
loadData
Load data asynchronously
function(node)
-
loadedKeys
(Controlled) Set loaded tree nodes. Need work with loadData
string[]
[]
multiple
Allows selecting multiple treeNodes
boolean
false
selectable
whether can be selected
boolean
true
selectedKeys
(Controlled) Specifies the keys of the selected treeNodes
string[]
-
showIcon
Shows the icon before a TreeNode's title. There is no default style; you must set a custom style for it if set to true
boolean
false
switcherIcon
customize collapse/expand icon of tree node
ReactNode
-
showLine
Shows a connecting line
booleanboolean|{showLeafIcon: boolean}
false
treeData
treeNodes data Array, if set it then you need not to construct children TreeNode. (key should be unique across the whole array)
array\<{ key, title, children, [disabled, selectable] }>
-
virtual
Disable virtual scroll when set to false
boolean
true
onCheck
Callback function for when the onCheck event occurs
function(checkedKeys, e:{checked: bool, checkedNodes, node, event, halfCheckedKeys})
-
onDragEnd
Callback function for when the onDragEnd event occurs
function({event, node})
-
onDragEnter
Callback function for when the onDragEnter event occurs
function({event, node, expandedKeys})
-
onDragLeave
Callback function for when the onDragLeave event occurs
function({event, node})
-
onDragOver
Callback function for when the onDragOver event occurs
function({event, node})
-
onDragStart
Callback function for when the onDragStart event occurs
function({event, node})
-
onDrop
Callback function for when the onDrop event occurs
function({event, node, dragNode, dragNodesKeys})
-
onExpand
Callback function for when a treeNode is expanded or collapsed
function(expandedKeys, {expanded: bool, node})
-
onLoad
Callback function for when a treeNode is loaded
function(loadedKeys, {event, node})
-
onRightClick
Callback function for when the user right clicks a treeNode
function({event, node})
-
onSelect
Callback function for when the user clicks a treeNode
function(selectedKeys, e:{selected: bool, selectedNodes, node, event})
-
icon
customize treeNode icon.
ReactNode | (props) => ReactNode
-
TreeNode props
PropertyDescriptionTypeDefault
checkable
When Tree is checkable, set TreeNode display Checkbox or not
boolean
-
disableCheckbox
Disables the checkbox of the treeNode
boolean
false
disabled
Disables the treeNode
boolean
false
icon
customize icon. When you pass component, whose render will receive full TreeNode props as component props
ReactNode | (props) => ReactNode
-
isLeaf
Determines if this is a leaf node(effective when loadData is specified)
boolean
false
key
Used with (default)ExpandedKeys / (default)CheckedKeys / (default)SelectedKeys. P.S.: It must be unique in all of treeNodes of the tree!
string
internal calculated position of treeNode
selectable
Set whether the treeNode can be selected
boolean
true
title
Title
string|ReactNode
---
DirectoryTree props
PropertyDescriptionTypeDefault
expandAction
Directory open logic, optional false 'click' 'doubleClick'
string
click
Tree Methods
NameDescriptionVersion
scrollTo({ key })
Scroll to key item in virtual scroll