Tree view
React Bootstrap 5 Tree view plugin
MDB treeview plugin is used to show hierarchical information which starts from the root item and proceed to its children and their respective children. Each item besides the root has a parent and can have children.
The parent is the node which is higher in the hierarchy and the child the one that is lower. Siblings are items which have one and the same parent. Items can be expanded and collapsed.
Note: Read the API tab to find all available options and advanced customization
Basic example - JSX
- One
- Two
-
Three
- Second-one
- Second-two
-
Second-three
-
Third-one
- Fourth-one
- Fourth-two
- Fourth-three
- Third-two
-
Third-three
- Fourth-one
- Fourth-two
- Fourth-three
-
Third-one
Basic example - JavaScript
You can define whole structure of tree using only JavaScript. There are some props in data that you can use to customize it:
Open on item click
Use a openOnItemClick
to define opening lists of treeview by click only on
the arrow or on the whole list item.
- One
- Two
-
Three
- Second-one
- Second-two
-
Second-three
-
Third-one
- Fourth-one
- Fourth-two
- Fourth-three
- Third-two
-
Third-three
- Fourth-one
- Fourth-two
- Fourth-three
-
Third-one
Selectable
Use a selectable
property to set up checkboxes in every list item.
- One
- Two
-
Three
- Second-one
- Second-two
-
Second-three
-
Third-one
- Fourth-one
- Fourth-two
- Fourth-three
- Third-two
-
Third-three
- Fourth-one
- Fourth-two
- Fourth-three
-
Third-one
Expand
- One
- Two
-
Three
- Second-one
- Second-two
-
Second-three
-
Third-one
- Fourth-one
- Fourth-two
- Fourth-three
- Third-two
-
Third-three
- Fourth-one
- Fourth-two
- Fourth-three
-
Third-one
Collapse
- One
- Two
-
Three
- Second-one
- Second-two
-
Second-three
-
Third-one
- Fourth-one
- Fourth-two
- Fourth-three
- Third-two
-
Third-three
- Fourth-one
- Fourth-two
- Fourth-three
-
Third-one
Custom icons - JSX
Use a rotationAngle
property to define a rotation angle of nested
lists icons.
- One
- Two
-
Three
- Second-one
- Second-two
-
Second-three
- Third-one
- Third-two
- Third-three
Custom icons - JavaScript
Add icons to the list elements by pasting an icon code in the
name
property. If you want to change the rotatable icon in the nested list - use
icon
property instead.
Color
Set the color of an active item using the
color
property.
Current color: primary
- One
- Two
-
Three
- Second-one
- Second-two
-
Second-three
-
Third-one
- Fourth-one
- Fourth-two
- Fourth-three
- Third-two
-
Third-three
- Fourth-one
- Fourth-two
- Fourth-three
-
Third-one
Line
Use a line
property to set up an additional line in every nested list.
- One
- Two
-
Three
- Second-one
- Second-two
-
Second-three
-
Third-one
- Fourth-one
- Fourth-two
- Fourth-three
- Third-two
-
Third-three
- Fourth-one
- Fourth-two
- Fourth-three
-
Third-one
Disabled - JSX
- One
- Two
-
Three
- Second-one
- Second-two
-
Second-three
-
Third-one
- Fourth-one
- Fourth-two
- Fourth-three
- Third-two
-
Third-three
- Fourth-one
- Fourth-two
- Fourth-three
-
Third-one
Disabled - JavaScript
To generate a disabled list item, use disabled
property.
Tree view - API
Import
Properties
MDBTreeview
Name | Type | Default | Description | Example |
---|---|---|---|---|
color
|
string | 'primary' |
Defines a text and background color for an active or hovered item |
<MDBTreeview color='secondary' />
|
getSelectedItem
|
(item: React.MutableObjectRef<any>) => void |
|
Returns an item after selection |
<MDBTreeview getSelectedItem={(item: any) => console.log(item)} />
|
items
|
Record<string,any> | [] |
Defines an array of children to render |
<MDBTreeview items={childrenArray} />
|
line
|
boolean | false |
Adds a line to every nested list |
<MDBTreeview line />
|
openOnItemClick
|
boolean | true |
Enables opening list by clicking only on the icon |
<MDBTreeview openOnItemClick={false} />
|
selectable
|
boolean | false |
Setup checkboxes for the every list item |
<MDBTreeview selectable />
|
treeviewRef
|
React.MutableObjectRef<any> |
|
A reference for the treeview component |
<MDBTreeview treeviewRef={someRef} />
|
MDBTreeviewItem
Name | Type | Default | Description | Example |
---|---|---|---|---|
disabled
|
boolean |
|
Disables and item (with all children) |
<MDBTreeviewItem disabled />
|
icon
|
string | 'angle-right' |
Defines a custom expanding icon for the nested list |
<MDBTreeviewItem icon='angle-down' />
|
itemRef
|
React.MutableObjectRef<any> |
|
A reference for the item element |
<MDBTreeviewItem itemRef={someRef} />
|
name
|
React,ComponentProps<any> | '' |
Defines an item text |
<MDBTreeviewItem name='One' />
|
rotationAngle
|
number | 90 |
Defines a rotation angle of the icons in nested lists |
<MDBTreeviewItem rotationAngle={180} />
|
show
|
boolean | false |
Defines if list is opened or not by default |
<MDBTreeviewItem subtree show />
|
subtree
|
boolean | false |
Declares a subtree item |
<MDBTreeviewItem subtree />
|
Events
MDBTreeview
Name | Type | Description |
---|---|---|
getSelectedItem
|
(item: React.MutableObjectRef<any>) => void | Returns an item after selection |