react-digraph icon indicating copy to clipboard operation
react-digraph copied to clipboard

Support For onDoubleClickNode

Open jordanparker6 opened this issue 5 years ago • 1 comments

onDoubleClickNode

It would be great to have a handler that would execute actions after a double click on a node. The native onDoubleClick property of the element doesn't work when an onClick property is set.

An onDoubleClickNode method would be ideal.

I have tried to use useRef and useState hooks to emulate a double click outside of the component to no success. I am new to React so help here would be appreciated.

jordanparker6 avatar Dec 20 '19 04:12 jordanparker6

You could always setup a timeout on top of the on click that handles checking for a second click.

So something like:

doubleClickPending = false;
doubleClickTimeout;

onClick(node) {
   if(this.doubleClickPending) {
      //It's a double click!
      this.doubleClickPending = false;
      clearTimeout(this.doubleClickTimeout);
   } else {
      this.doubleClickPending = true;
      this.doubleClickTimeout = setTimeout(() => {
         this.doubleClickPending = false;
      }, 400);
   }
}

Obviously, just double check the node that's been clicked on is the same as the one from before.

Hopefully that helps...

iChaosren avatar Dec 20 '19 06:12 iChaosren