diff --git a/index.js b/index.js index 725208f..6c4d527 100644 --- a/index.js +++ b/index.js @@ -3,20 +3,25 @@ import React, { Component, PropTypes } from 'react' export default class ClickOutside extends Component { static propTypes = { - onClickOutside: PropTypes.func.isRequired + onClickOutside: PropTypes.func.isRequired, + useCapture: PropTypes.bool + }; + + static defaultProps = { + useCapture: true }; render() { - const { children, onClickOutside, ...props } = this.props + const { children, onClickOutside, useCapture, ...props } = this.props return
this.container = ref}>{children}
} componentDidMount() { - document.addEventListener('click', this.handle, true) + document.addEventListener('click', this.handle, this.props.useCapture) } componentWillUnmount() { - document.removeEventListener('click', this.handle, true) + document.removeEventListener('click', this.handle, this.props.useCapture) } handle = e => {