Can not prevent a child onClick event from the parent's onMouseUp event
See original GitHub issueI do click down, mouse move, and click up (all this events apply within element area).
Events onMouseDown
, onMouseMove
, onMouseUp
defined on the parent element SwipePanel
.
So I try prevent onClick
event on Element
component such way:
class SwipePanel extends React.Component {
handleMouseUp(event) {
if(event.nativeEvent) {
event.nativeEvent.preventDefault();
event.nativeEvent.stopPropagation();
}
event.preventDefault();
event.stopPropagation();
console.log('SwipePanel onMouseUp');
}
...
}
class Element extends React.Component {
handleMouseClick(event) {
console.log('Element onClick');
}
...
}
Via console.log
I see
SwipePanel onMouseUp
Element onClick
So I need prevent childs’s onClick
event from parent component via onMouseUp
. I am using React v0.14.3
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Prevent child's onclick after mouseup on parent?
Is there any way to prevent the click event from happening in the child, after the mouseup event has been triggered in the...
Read more >SyntheticEvent - React
This reference guide documents the SyntheticEvent wrapper that forms part of React's Event System. See the Handling Events guide to learn more.
Read more >ASP.NET Core Blazor event handling - Microsoft Learn
An onclick event occurring in the child component is a common use case. To expose events across components, use an EventCallback. A parent...
Read more >Element: click event - Web APIs | MDN
An element receives a click event when a pointing device button (such as a mouse's primary mouse button) is both pressed and released...
Read more >Handling Events :: Eloquent JavaScript
<button>Click me</button> <p>No handler here. ... For most event types, handlers registered on nodes with children will also receive events that happen in ......
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
@nodkz You can use
onClickCapture
in parent component andstopPropagation
if event target is not child component.https://facebook.github.io/react/docs/events.html#supported-events
Another method that I’ve found to be quite straightforward for child
onClick
ignoring. Give the parent a unique ID. Perhaps"swipe-panel"
in your example. Then In the parent’sonClick
: