Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stopPropagation is not stopping events from bubble up #60

Open
adamchenwei opened this issue Nov 28, 2016 · 5 comments
Open

stopPropagation is not stopping events from bubble up #60

adamchenwei opened this issue Nov 28, 2016 · 5 comments

Comments

@adamchenwei
Copy link

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?

@jordan-burnett
Copy link

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

@adamchenwei
Copy link
Author

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

@jjmax75
Copy link

jjmax75 commented Aug 2, 2017

@jjmax75
Copy link

jjmax75 commented Aug 2, 2017

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

@booherbg
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants