patternfly-bootstrap-treeview icon indicating copy to clipboard operation
patternfly-bootstrap-treeview copied to clipboard

How to add the method of double clicking a node?

Open DDNANA2013 opened this issue 7 years ago • 1 comments

I have a situation of double clicking one node ,how can I add this method ?or could anyone give me some signs? thanks.

DDNANA2013 avatar Jan 08 '18 07:01 DDNANA2013

I achieved this with a trick so ugly you would become unsane by reading it... (Lovecraft fans here ;)?)

As I noticed, the system of catching events only uses bubbling and never capture. When you select a node, it first calls "onNodeUnselected" for the previous one, then the "onNodeSelected". HOWEVER. If you select the same node, only the "onNodeUnselected" is fired. And after all this, the "global" click event I've bound manually is fired on the tree.

So here's what I've done :

  • "onNodeSelected" : have a variable that stores the current selected node and check for your node if it has a "double-clicked" argument for your logic...
  • "onNodeUnselected" : prevent unselection with a return (if it is the same one for example, my case was a little bit more complicated)
  • "onTreeClicked" : check if the node you tried to unselect is the same that fired the clicked event (with event.target). If it has, define your node as "double-clicked", then (and that's ugly and heavy but had no better idea yet :/ ) FIND the node in the tree (copying it didn't worked for me), and then apply the "selectNode" method with a {silent : false}.

I hope you can work from that! (even if I'm 6 months too late...)

Holywa avatar Jun 18 '18 13:06 Holywa