Callback Props
Callback props allow you to respond to user interactions and customize behavior during drag-and-drop operations, node expansion, and other tree events.generateNodeProps
Generate additional props to be passed to each node renderer. Use this to add buttons, custom styles, class names, or modify the title rendering for individual nodes.
TypeScript Signature
Parameters
data.node: The tree node objectdata.path: The path to the node (array of indices)data.treeIndex: The index of the node in the flattened treedata.parentNode: The parent node (if any)data.lowerSiblingCounts: Array of sibling counts at each leveldata.isSearchMatch: Whether the node matches the current searchdata.isSearchFocus: Whether the node is the focused search result
Returns
Object with optional properties:buttons: Array of React elements to display as action buttonstitle: Function that returns a custom title elementstyle: CSS styles to apply to the nodeclassName: CSS class name for the node
Example: Adding Buttons
Example: Conditional Styling
Example: Custom Title Renderer
Example: Context-Aware Buttons
onMoveNode
Called after a node has been successfully moved to a new position in the tree via drag-and-drop.
TypeScript Signature
Parameters
data.node: The moved nodedata.treeIndex: Current tree indexdata.path: Current pathdata.treeData: Updated tree data after the movedata.prevTreeIndex: Tree index before the movedata.prevPath: Path before the movedata.nextTreeIndex: Tree index after the movedata.nextPath: Path after the movedata.nextParentNode: New parent node (null if root level)
Example: Logging Moves
Example: Syncing with Backend
Example: Tracking Hierarchy Changes
onVisibilityToggle
Called when a node’s children are expanded or collapsed.
TypeScript Signature
Parameters
data.treeData: The updated tree datadata.node: The node that was toggleddata.expanded: True if expanded, false if collapsed
Example: Tracking Expansion
Example: Persisting Expansion State
Example: Lazy Loading Children
onDragStateChanged
canDrag
Determines whether a node can be dragged. Can be a boolean to enable/disable dragging for all nodes, or a function to control dragging per node.
TypeScript Signature
Parameters (when function)
data.node: The tree nodedata.path: Path to the nodedata.treeIndex: Index in the flattened treedata.parentNode: Parent nodedata.lowerSiblingCounts: Sibling counts at each leveldata.isSearchMatch: Whether node matches searchdata.isSearchFocus: Whether node is focused search result
Example: Disable All Dragging
Example: Conditional Dragging
Example: Role-Based Dragging
canDrop
Determines whether a dragged node can be dropped at a specific location.
TypeScript Signature
Parameters
data.node: The node being draggeddata.prevPath: Path before the dropdata.prevParent: Parent before the dropdata.nextPath: Proposed path after the dropdata.nextParent: Proposed parent after the drop
Example: Restrict Folder Structure
Example: Prevent Circular Dependencies
Example: Enforce Depth Limits
canNodeHaveChildren
Related Props
- See Required Props for
onChangeandgetNodeKeydetails - See Behavior Props for
maxDepthwhich complements drag-drop restrictions - See Search Props for
searchFinishCallbackwhich is another callback type