JedWatson / react-tappable

Tappable component for React

Home Page:http://jedwatson.github.io/react-tappable/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stop Propagation for nested button

nocksock opened this issue · comments

I have a button inside of a tappable element that has an on click handler. How can I prevent tappable to be triggered when that button is clicked?

<Tappable onTap={()=>doSomething()}>
    <SomeComponentThatHasAButton />
</Tappable>

So inside of SomeComponentThatHasAButton is a button – but Tappable's onTap is still triggered. How to stop this?

NOTE: This also does not work if I change the button to a Tappable-Component.

if the inner button is a Tappable, just add the stopPropagation prop to prevent the tap propagating up to its parent.
if the inner button is NOT a Tappable, then you'll need to call stopPropagation from the click event, and use https://github.com/ftlabs/fastclick to make sure it works on mobile.

Awesome! This seems to have fixed it. Thanks.