From 260772b58c97eb4eec7a2933304360973ba7065a Mon Sep 17 00:00:00 2001 From: Jeffrey Horn Date: Fri, 7 Oct 2016 15:45:54 -0700 Subject: [PATCH] add shouldClickOutside --- index.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 725208f..5274bbf 100644 --- a/index.js +++ b/index.js @@ -3,11 +3,16 @@ import React, { Component, PropTypes } from 'react' export default class ClickOutside extends Component { static propTypes = { - onClickOutside: PropTypes.func.isRequired + onClickOutside: PropTypes.func.isRequired, + shouldClickOutside: PropTypes.func + }; + + static defaultProps = { + shouldClickOutside: () => true }; render() { - const { children, onClickOutside, ...props } = this.props + const { children, onClickOutside, shouldClickOutside, ...props } = this.props return
this.container = ref}>{children}
} @@ -20,8 +25,8 @@ export default class ClickOutside extends Component { } handle = e => { - const { onClickOutside } = this.props + const { onClickOutside, shouldClickOutside } = this.props const el = this.container - if (!el.contains(e.target)) onClickOutside(e) + if (!el.contains(e.target) && shouldClickOutside(e)) onClickOutside(e) }; }