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) }; }