react-digraph
react-digraph copied to clipboard
Support For onDoubleClickNode
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.
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...