dunnock / react-sigma

Lightweight React library for drawing network graphs built on top of SigmaJS
https://dunnock.github.io/react-sigma/
MIT License
258 stars 43 forks source link

onDoubleClick eventHandler to add more interactive actions #131

Open michaelbdavid opened 1 year ago

michaelbdavid commented 1 year ago

I'd like to add onDoubleClick eventhandler does this exist?

undefined-box commented 1 year ago

Hi there!

Yes, the double click event exists; here are two possible implementations: (from MDN).

addEventListener('dblclick', (event) => {});
ondblclick = (event) => { };

And here some docs: https://developer.mozilla.org/en-US/docs/Web/API/Element/dblclick_event https://caniuse.com/mdn-api_element_dblclick_event

Hope this helps!

michaelbdavid commented 1 year ago

Thanks for the reply. I guess I'm a newb here is there away to add double click handler when clicking on the nodes? I basically want to override the current behavior of zooming in if a node is dblclicked.

Tried to do something like:

×
←→1 of 2 errors on the page
TypeError: _sigma$current.addEventListener is not a function
(anonymous function)
  64 | const onDblClick = (event: any) => {
  65 |     console.log('dblclick', event);
  66 | };
> 67 | sigma.current?.addEventListener('dblclick', onDblClick);
     | ^  68 | 
  69 | return () => {
  70 |     sigma.current?.removeEventListener('dblclick', onDblClick);

also tried sigma.current.bind('dblclick', onDblClick) as well

where sigma.current is a ref on the Sigma component. and no joy...

Any thoughts?