Skip to content

Tree

Hierarchical list with expand/collapse, checkboxes, and drag-and-drop.

Import

ts
import { Tree } from '@itsmemyk/react-tree-grid/tree'

Props

PropTypeDefaultDescription
dataTreeNode[]Tree data (required)
checkboxbooleanfalseShow checkboxes on all nodes
editablebooleanfalseAllow double-click to rename labels
dragItem'item' | 'both''item': nodes are drag sources; 'both': sources and drop targets
virtualbooleanfalseEnable virtual scrolling for flat trees
expandedstring[]Controlled expanded node IDs
defaultExpandedstring[]Initial expanded state (uncontrolled)
selectedstring[]Controlled selected node IDs
checkedstring[]Controlled checked node IDs
cssstringExtra CSS class on root element

Events

PropSignatureDescription
onSelect(id: string) => voidFires when a node is clicked
onCheck(ids: string[]) => voidFires when a checkbox changes; receives full checked set
onExpand(id: string) => voidFires when a node is expanded
onCollapse(id: string) => voidFires when a node is collapsed
onEdit(id: string, newValue: string) => voidFires after label edit confirmed
onDrop(dragId, targetId, position) => voidFires after drag-drop; position: 'before' | 'after' | 'inside'

TreeRef (ref)

tsx
import { useRef } from 'react'
import type { TreeRef } from '@itsmemyk/react-tree-grid/tree'

const ref = useRef<TreeRef>(null)

<Tree ref={ref} data={data} />
MethodSignatureDescription
expand(id: string) => voidExpand a node
collapse(id: string) => voidCollapse a node
expandAll() => voidExpand all nodes
collapseAll() => voidCollapse all nodes
select(ids: string[]) => voidSet selected nodes
check(ids: string[]) => voidSet checked nodes

Released under the MIT License.