JedWatson / react-tappable

Tappable component for React
http://jedwatson.github.io/react-tappable/
MIT License
862 stars 90 forks source link

Proposal: onTapOutside event #26

Closed lo1tuma closed 9 years ago

lo1tuma commented 9 years ago

Hi,

I want to implement a touch-friendly dropdown button which opens a submenu on a tap event and should close the submenu if a tap event is triggered somewhere outside of the dropdown button.

Similar modules:

clauderic commented 9 years ago

An easier way to achieve the same result would just be to have a <Tappable> backdrop (be it visible or not, through opacity) and playing with z-index

JedWatson commented 9 years ago

Thanks for the suggestion @lo1tuma

I agree with @clauderic, there is a lot of detail involved in how you might implement onTapOutside, including assumptions I'm not currently happy making in this component.

Specifically, there may be other elements which could block (or otherwise handle) the tap event in your page that could conflict with the handler we set up.

It seems clearer and simpler for cases like the one you've got to just implement the tappable backdrop behind the submenu component you're implementing.