@@ -10,7 +10,7 @@ import TransitionGroupWrapper from './TransitionGroupWrapper';
1010import Node from '../Node' ;
1111import Link from '../Link' ;
1212import { TreeNodeDatum , Point , RawNodeDatum } from '../types/common' ;
13- import { TreeLinkEventCallback , TreeNodeEventCallback , TreeProps } from './types' ;
13+ import { TreeLinkEventCallback , TreeProps } from './types' ;
1414import globalCss from '../globalCss' ;
1515
1616type TreeState = {
@@ -303,12 +303,15 @@ class Tree extends React.Component<TreeProps, TreeState> {
303303 /**
304304 * Handles the user-defined `onNodeClick` function.
305305 */
306- handleOnNodeClickCb : TreeNodeEventCallback = ( hierarchyPointNode , evt ) => {
306+ handleOnNodeClickCb = ( nodeId : string , evt : SyntheticEvent ) => {
307307 const { onNodeClick } = this . props ;
308308 if ( onNodeClick && typeof onNodeClick === 'function' ) {
309+ const data = clone ( this . state . data ) ;
310+ const matches = this . findNodesById ( nodeId , data , [ ] ) ;
311+ const targetNode = matches [ 0 ] ;
309312 // Persist the SyntheticEvent for downstream handling by users.
310313 evt . persist ( ) ;
311- onNodeClick ( clone ( hierarchyPointNode ) , evt ) ;
314+ onNodeClick ( clone ( targetNode ) , evt ) ;
312315 }
313316 } ;
314317
@@ -327,12 +330,15 @@ class Tree extends React.Component<TreeProps, TreeState> {
327330 /**
328331 * Handles the user-defined `onNodeMouseOver` function.
329332 */
330- handleOnNodeMouseOverCb : TreeNodeEventCallback = ( hierarchyPointNode , evt ) => {
333+ handleOnNodeMouseOverCb = ( nodeId : string , evt : SyntheticEvent ) => {
331334 const { onNodeMouseOver } = this . props ;
332335 if ( onNodeMouseOver && typeof onNodeMouseOver === 'function' ) {
336+ const data = clone ( this . state . data ) ;
337+ const matches = this . findNodesById ( nodeId , data , [ ] ) ;
338+ const targetNode = matches [ 0 ] ;
333339 // Persist the SyntheticEvent for downstream handling by users.
334340 evt . persist ( ) ;
335- onNodeMouseOver ( clone ( hierarchyPointNode ) , evt ) ;
341+ onNodeMouseOver ( clone ( targetNode ) , evt ) ;
336342 }
337343 } ;
338344
@@ -351,12 +357,15 @@ class Tree extends React.Component<TreeProps, TreeState> {
351357 /**
352358 * Handles the user-defined `onNodeMouseOut` function.
353359 */
354- handleOnNodeMouseOutCb : TreeNodeEventCallback = ( hierarchyPointNode , evt ) => {
360+ handleOnNodeMouseOutCb = ( nodeId : string , evt : SyntheticEvent ) => {
355361 const { onNodeMouseOut } = this . props ;
356362 if ( onNodeMouseOut && typeof onNodeMouseOut === 'function' ) {
363+ const data = clone ( this . state . data ) ;
364+ const matches = this . findNodesById ( nodeId , data , [ ] ) ;
365+ const targetNode = matches [ 0 ] ;
357366 // Persist the SyntheticEvent for downstream handling by users.
358367 evt . persist ( ) ;
359- onNodeMouseOut ( clone ( hierarchyPointNode ) , evt ) ;
368+ onNodeMouseOut ( clone ( targetNode ) , evt ) ;
360369 }
361370 } ;
362371
@@ -500,14 +509,12 @@ class Tree extends React.Component<TreeProps, TreeState> {
500509 ) ;
501510 } ) }
502511
503- { nodes . map ( ( hierarchyPointNode , i ) => {
504- const { data, x, y, parent } = hierarchyPointNode ;
512+ { nodes . map ( ( { data, x, y, parent, ...rest } , i ) => {
505513 return (
506514 < Node
507515 key = { 'node-' + i }
508516 data = { data }
509517 position = { { x, y } }
510- hierarchyPointNode = { hierarchyPointNode }
511518 parent = { parent }
512519 nodeClassName = { this . getNodeClassName ( parent , data ) }
513520 renderCustomNodeElement = { renderCustomNodeElement }
0 commit comments