React click outside component.
$ npm install folkapp/react-click-outside
ClickOutside takes two props:
onClickOutside
(required): function that closes the<ClickOutside />
elementexceptions
: an array of references on which we don't want the click outside event to be triggered
<div
ref={(ref) => this.setState({except: ref})}
onClick={handleOpening}
>
Open the menu or something
</div>
<ClickOutside
onClickOutside={::this.close}
exceptions={[this.state.except]}
>
<p>Im a menu or something that you want to hide when clicking outside.</p>
</ClickOutside>
tjholowaychuk.com · GitHub @tj · Twitter @tjholowaychuk