[Bug] Unable to stop node click propagation to prevent selection
See original GitHub issueWhen 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.
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:
- Created 3 years ago
- Reactions:1
- Comments:6 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@moklick I didn’t. This wasn’t documented anywhere; at least, not anywhere obvious. I’ve updated the Codesandbox and can confirm adding the
nodragclass to the button makes it work as expected.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.