question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Unable to stop node click propagation to prevent selection

See original GitHub issue

When handling a click within a node, it’s not possible to prevent the “click” from selecting the node using event.stopPropagation() as one might expect.

Edit react-flow-unable-to-stop-propagation

It appears that both onDragStart and onDragStop (the latter when selectNodesOnDrag: false) will select the node.

Unfortunately, this has cost me a good few hours and I’m sure others might do the same.


Workaround

To work around this issue, it is necessary to block the mousedown event from propagating.

<button onClick={handleClick} onMouseDown={event => event.stopPropagation()}>

I can work with this for now, but it might be worth adding some documentation around this so this is less likely to be raised as an issue by others.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
justrhysismcommented, Dec 2, 2020

@moklick I didn’t. This wasn’t documented anywhere; at least, not anywhere obvious. I’ve updated the Codesandbox and can confirm adding the nodrag class to the button makes it work as expected.

1reaction
justrhysismcommented, Dec 3, 2020

I think it also needs to be re-titled, as I wasn’t trying to prevent dragging, I was looking to prevent selection. Reading the docs there wouldn’t have helped me as it didn’t present the answer to the question I had.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stop click event propagation | React - EJ 2 Forums - Syncfusion
I'm using HTML nodes which has buttons in them and am unable to prevent the selection of node when clicking on the button...
Read more >
Right click stop propagation - javascript - Stack Overflow
I've just run into the same problem, trying to prevent right-clicks from propagating. Firefox versions 25, 29, and 31 all have this behaviour...
Read more >
Event.stopPropagation() - Web APIs | MDN
The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.
Read more >
When to actually use preventDefault(), stopPropagation(), and ...
The author of The Dangers of Stopping Event Propagation blames the authors of 'jquery-ujs' for calling stopPropagation() but we'll see ...
Read more >
The Dangers of Stopping Event Propagation - CSS-Tricks
This bug happens because the Bootstrap code responsible for closing the dropdown menu is listening for click events on the document. But since ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found