diff --git a/README.md b/README.md index 8dc52e88c..6cc7049db 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ class | data-class | String | | extra custom class, can use !important to afterHide | null | Func | () => {} | Function that will be called after tooltip hide disable | data-tip-disable | Bool | true, false | Disable the tooltip behaviour, default is false scrollHide | data-scroll-hide | Bool | true, false | Hide the tooltip when scrolling, default is true + resizeHide | null | Bool | true, false | Hide the tooltip when resizing the window, default is true ## Using react component as tooltip Check the example [React-tooltip Test](http://wwayne.com/react-tooltip) diff --git a/src/decorators/windowListener.js b/src/decorators/windowListener.js index 2489091cf..d74aebecb 100644 --- a/src/decorators/windowListener.js +++ b/src/decorators/windowListener.js @@ -4,7 +4,7 @@ import CONSTANT from '../constant' export default function (target) { - target.prototype.bindWindowEvents = function () { + target.prototype.bindWindowEvents = function (resizeHide) { // ReactTooltip.hide window.removeEventListener(CONSTANT.GLOBAL.HIDE, this.hideTooltip) window.addEventListener(CONSTANT.GLOBAL.HIDE, this.hideTooltip, false) @@ -18,8 +18,10 @@ export default function (target) { window.addEventListener(CONSTANT.GLOBAL.SHOW, this.globalShow, false) // Resize - window.removeEventListener('resize', this.onWindowResize) - window.addEventListener('resize', this.onWindowResize, false) + if (resizeHide) { + window.removeEventListener('resize', this.onWindowResize) + window.addEventListener('resize', this.onWindowResize, false) + } } target.prototype.unbindWindowEvents = function () { diff --git a/src/index.js b/src/index.js index 3ceb03fd4..1bd47da73 100644 --- a/src/index.js +++ b/src/index.js @@ -44,8 +44,13 @@ class ReactTooltip extends Component { afterShow: PropTypes.func, afterHide: PropTypes.func, disable: PropTypes.bool, - scrollHide: PropTypes.bool - } + scrollHide: PropTypes.bool, + resizeHide: PropTypes.bool + }; + + static defaultProps = { + resizeHide: true + }; constructor (props) { super(props) @@ -95,7 +100,7 @@ class ReactTooltip extends Component { componentDidMount () { this.setStyleHeader() // Set the style to the this.bindListener() // Bind listener for tooltip - this.bindWindowEvents() // Bind global event for static method + this.bindWindowEvents(this.props.resizeHide) // Bind global event for static method } componentWillReceiveProps (props) {