Behavior Props
Behavior props control how the tree functions, including depth limits, direction, virtualization, and drag-and-drop behavior.maxDepth
Maximum depth that nodes can be nested. Use this to limit how deeply items can be nested in the tree hierarchy.
TypeScript Signature
Default
undefined (infinite depth)Example: Limit to 3 Levels
Example: Flat List (No Nesting)
Example: Dynamic Depth Limit
Use Cases
- Category systems: Limit categories to 2-3 levels
- File systems: Prevent overly deep folder structures
- Organization charts: Enforce a maximum management hierarchy
- Menu builders: Limit navigation menu depth
maxDepth counts from 1. A maxDepth of 1 means only root-level items with no children allowed.rowDirection
Direction in which tree rows are rendered. Use
'rtl' (right-to-left) for languages like Arabic or Hebrew.TypeScript Signature
Default
'ltr' (left-to-right)Example: Right-to-Left Tree
Example: Dynamic Direction Based on Locale
Visual Difference
- LTR: Expand/collapse icons and indentation on the left
- RTL: Expand/collapse icons and indentation on the right
Changing
rowDirection only affects the tree structure layout. You’ll need to handle text direction separately using CSS direction property or dir attribute.isVirtualized
Whether to use virtualization for rendering the tree. Virtualization significantly improves performance for large trees by only rendering visible nodes.
TypeScript Signature
Default
trueWhen to Use Virtualization (Default)
- Trees with hundreds or thousands of nodes
- Performance is critical
- Tree height is constrained (has a fixed height container)
When to Disable Virtualization
- Very small trees (< 100 nodes)
- Need to support browser’s native find (Ctrl+F)
- Need to print the entire tree
- Using features that conflict with virtualization
Example: Disable Virtualization
Example: Small Printable Tree
Example: Conditional Virtualization
Performance Comparison
| Tree Size | Virtualized | Non-Virtualized |
|---|---|---|
| 100 nodes | ~16ms | ~18ms |
| 1,000 nodes | ~16ms | ~150ms |
| 10,000 nodes | ~16ms | ~1500ms+ |
dndType
The drag-and-drop type identifier used by react-dnd. Required when integrating with external drag sources or drop targets.
TypeScript Signature
Default
'REACT_APPLE_TREE_ITEM'Example: Basic Usage
Example: External Drag Sources
Example: Multiple Trees
All trees that should allow cross-dragging must use the same
dndType value.shouldCopyOnOutsideDrop
Determines whether nodes should be copied (instead of moved) when dropped outside the tree to external react-dnd drop targets.
TypeScript Signature
Default
false (nodes are removed from tree on outside drop)Example: Always Copy on Outside Drop
Example: Conditional Copying
Example: Copy with Modifier Key
Example: Tree to Trash Bin
Complete Example
Here’s a complete example combining multiple behavior props:Related Props
- See Callback Props for
canDropandcanNodeHaveChildrenwhich complement behavior controls - See Required Props for basic tree setup
- See Styling Props for visual customization