EV01 Live Event Monitor
Interact with the tree to see events fired in real-time
Interactive Tree
Event Log
Event Log
0Event Guide
How to Test Events:
- Click nodes to trigger
onNodeClicked - Start drag to trigger
onNodeDragStart - Drag over nodes for
onNodeDragOver - Drop to trigger
onNodeDrop
Event Statistics:
Total events logged: 0Log displays last 20 events
Events logged in real-time
EV02 Event Reference
All available events and callbacks for handling user interactions
Event Reference
| Callback / Event | Trigger | Signature | Description |
|---|---|---|---|
onNodeClickednode-clicked | User click | (node: TreeNode<T>) => void | Called when user clicks on any tree node |
onNodeDragStartnode-drag-start | Drag begins | (node, event: DragEvent) => void | Called when user starts dragging a node |
onNodeDragOvernode-drag-over | Drag over | (node, event: DragEvent) => void | Called when dragged node hovers over a target |
onNodeDropnode-drop | Drop | (dropNode, draggedNode, position, event, operation) => void | Extended signature with position and operation |
Two Approaches
Set callbacks as JS properties (tree.onNodeClicked = fn) or use addEventListener with kebab-case event names (tree.addEventListener('node-clicked', fn)). CustomEvent detail contains the same data.
Usage Examples
Implementation Guide
TreeNode Structure
All callbacks receive TreeNode<T> objects with:
path- Node's hierarchical pathdata- Your original data objectchildren- Child nodes mapisExpanded- Expansion stateisSelected- Selection state
CustomEvent Names
Events are dispatched with composed: true so they cross Shadow DOM boundaries. Event names use kebab-case.
Performance
- Callbacks are invoked synchronously
- Keep handlers lightweight
- Debounce expensive operations
EV03 onNodeDrop Deep Dive
Extended drop callback with position and operation support
Full Signature
| Parameter | Type | Description |
|---|---|---|
dropNode | TreeNode<T> | null | Target node, or null for root/empty tree drops |
draggedNode | TreeNode<T> | The node being dragged |
position | 'above' | 'below' | 'child' | Where to place relative to target |
event | DragEvent | TouchEvent | Original browser event (supports touch) |
operation | 'move' | 'copy' | Ctrl+drag = copy operation |
Implementation Examples
Drop Handling Guide
Position Values
'above'- Insert as sibling before target'below'- Insert as sibling after target'child'- Insert as child of target
Operation Types
'move'- Default drag operation'copy'- Ctrl+drag or copy drag
Null dropNode
dropNode is null when:
- Dropped on empty tree placeholder
- Dropped on root drop zone
Touch Support
The event can be TouchEvent on mobile devices with long-press drag.
EV04 Search API
Search is property-based — use searchText property and searchNodes method
Search Properties & Methods
| Property / Method | Type | Description |
|---|---|---|
search-text / searchText | string | Search query - filters tree automatically when set |
should-use-internal-search-index | boolean | Enable FlexSearch-based indexing for large trees |
search-value-member / searchValueMember | string | Property name to use for search text |
getSearchValueCallback (JS only) | (node) => string | Custom function to extract searchable text |
searchNodes() | (text: string) => TreeNode[] | Method: Query nodes programmatically |
filterNodes() | (text: string) => void | Method: Filter the tree display |
Note: Property-Based Search
Search uses reactive properties. Set searchText and the tree filters automatically. No search events are fired.
Search Implementation
Search Guide
Reactive Filtering
When searchText changes, the tree automatically filters to show matching nodes and their ancestors.
searchNodes() Method
Use tree.searchNodes(query) to query nodes without changing the display filter.
FlexSearch Integration
Enable should-use-internal-search-index for optimized search on large trees.
Custom Indexing
Use getSearchValueCallback to index multiple fields or apply custom text transformations.
EV05 Performance & Best Practices
Optimize event handling for large trees and complex applications
Best Practices
Do's
- Debounce expensive operations in callbacks
- Keep callback handlers lightweight
- Use
addEventListenerfor multiple listeners - Batch state updates when handling multiple events
- Check
dropNodefor null before accessing properties
Don'ts
- Don't perform heavy computations in callbacks
- Don't make synchronous API calls in handlers
- Don't manipulate tree DOM directly - use the API methods
- Don't forget to remove event listeners when component unmounts
- Don't forget null checks for dropNode
Cleanup
addEventListener, remember to call removeEventListener during cleanup.
Property callbacks (tree.onNodeClicked = null) are cleaned up automatically when the element is removed.Patterns
Performance Guide
Callback Performance
- Callbacks run synchronously - keep them fast
- Debounce API calls and heavy operations
- Use async/await for server operations
Event Patterns
- Property callbacks: Simple, one handler per event
- addEventListener: Multiple handlers, standard DOM pattern
- CustomEvents:
composed: truecrosses Shadow DOM
Large Trees
- Enable
should-use-internal-search-index - Use
expand-levelto limit initial render - Use virtual scroll for 5000+ nodes
Testing
Test event handlers by dispatching synthetic events or calling callbacks directly with mock TreeNode objects.