Skip to main content

TreeView

The TkTreeview component displays hierarchical data in a tree structure with expandable/collapsible nodes. Uses array-based data structure for better performance and easier data management.

import { TkTreeView } from '@takeoff-ui/react'

Basic​

The basic mode displays tree items in a traditional hierarchical structure with expandable/collapsible nodes.

View Code

Stepper Mode​

The stepper mode displays tree items in a step-by-step column layout, ideal for navigation and drill-down interfaces.

View Code

Selectable​

Enable checkbox selection with the selectable prop for multi-selection functionality. Use the value prop to control selected items and listen to tk-change events for selection updates.

Selected items: 0

View Code

const [selectedItems, setSelectedItems] = useState([]);

const treeData = [
{
key: 'documents',
label: 'Documents',
children: [
{
key: 'work-files',
label: 'Work Files',
children: [
{
key: 'reports',
label: 'Reports',
children: [
{
key: 'q1-report',
label: 'Q1 Report.pdf'
},
{
key: 'q2-report',
label: 'Q2 Report.pdf'
}
]
}
]
},
{
key: 'personal',
label: 'Personal',
children: [
{
key: 'photos',
label: 'Photos',
children: [
{
key: 'vacation-jpg',
label: 'Vacation.jpg'
}
]
},
{
key: 'notes-txt',
label: 'Notes.txt'
}
]
}
]
}
];

<TkTreeView
mode="basic"
type="light"
size="base"
items={treeData}
selectable={true}
value={selectedItems}
branchIcon="folder"
leafIcon="insert_drive_file"
onTkChange={(e) => setSelectedItems(e.detail)}

/>

<div>
<p>Selected items: {selectedItems.length}</p>
{selectedItems.length > 0 && (
<ul>
{selectedItems.map((key, index) => (
<li key={index}>{key}</li>
))}
</ul>
)}
</div>

Type​

The type prop controls the style type of the tree view. It can be set to basic, divided, or light.

View Code

Size​

The size prop controls the size of the tree view. It can be set to base, small, or large.

View Code

TreeView API​

Props​

NameTypeDefaultDescription
IBadgeOptionsnullBadge customization options for children count display.
string''Icon for branch items (items with children). When empty, no icon is shown.
booleanfalseIf true, disables all interaction with the tree view.
ITreeItem[][]Array of tree items data. This is the primary way to provide data to the tree view.
string''Icon for leaf items (items without children). When empty, no icon is shown.
"basic", "stepper"'basic'Tree view mode: 'basic' or 'stepper'.
booleanfalseIf true, enables checkbox selection for tree items.
booleantrueShow/hide the badge for children count on directories.
booleantrueShow/hide the pointer icon for selected items.
"base", "large", "small"'base'Tree view size: 'large', 'base' or 'small'.
"basic", "divided", "light"'basic'Tree view type: 'basic', 'divided', or 'light'.
string[]nullThe value of the selected tree item.

Events​

NameDescription
tk-changeEvent emitted when the selected value changes.
tk-item-clickEvent emitted when a tree item is clicked.