react-hammerjs icon indicating copy to clipboard operation
react-hammerjs copied to clipboard

stopPropagation is not stopping events from bubble up

Open adamchenwei opened this issue 9 years ago • 5 comments

I have a child element using onTap and a parent element using onTap as well. But seems the stopPropagation for both is not seems stopping the event from firing, both function has the stopPropagation are firing regardless... any fix or clue?

adamchenwei avatar Nov 28 '16 17:11 adamchenwei

Same issue, though rather 'stopPropagation' isn't exposed in the event object, so I have no option for nested handlers at all.

jordan-burnett avatar Dec 21 '16 14:12 jordan-burnett

@jordan-burnett I had to switch the top level to hammer as well, totally not a good solution but works for now

adamchenwei avatar Dec 21 '16 16:12 adamchenwei

Found this - https://gist.github.com/jtangelder/361052976f044200ea17 at HammerJS site- http://hammerjs.github.io/tips/

jjmax75 avatar Aug 02 '17 08:08 jjmax75

I've found a solution that works for me, might be helpful to others I believe the reason that stopPropogation is unavailable is that you call this on a child element so an event on that child doesn't bubble up the DOM tree. Hammer wraps the components so is the parent in the DOM. That's just my understanding, feedback would be welcome. My fix is to add a panned state to the parent component and then set this to true when hammer registers a pan, and false on mount and tap/press. This state is then passed down to the children elements that I want to prevent from receiving the click event. So:

onClick = { !this.props.panned ? props.unitClickHandler : null }

also, please check this post on SO - https://stackoverflow.com/a/25063214

jjmax75 avatar Aug 02 '17 10:08 jjmax75

For anyone who finds this later, I was able to get around this by using event.stopImmediatePropagation(). I experience no side effects, although YMMV.

booherbg avatar Sep 28 '17 16:09 booherbg