Skip to content

Commit 2e2483f

Browse files
authored
Merge pull request #194 from wwayne/resize-hide
Add resizeHide option
2 parents 45cc694 + 5e76465 commit 2e2483f

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class | data-class | String | | extra custom class, can use !important to
6767
afterHide | null | Func | () => {} | Function that will be called after tooltip hide
6868
disable | data-tip-disable | Bool | true, false | Disable the tooltip behaviour, default is false
6969
scrollHide | data-scroll-hide | Bool | true, false | Hide the tooltip when scrolling, default is true
70+
resizeHide | null | Bool | true, false | Hide the tooltip when resizing the window, default is true
7071

7172
## Using react component as tooltip
7273
Check the example [React-tooltip Test](http://wwayne.com/react-tooltip)

src/decorators/windowListener.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import CONSTANT from '../constant'
55

66
export default function (target) {
7-
target.prototype.bindWindowEvents = function () {
7+
target.prototype.bindWindowEvents = function (resizeHide) {
88
// ReactTooltip.hide
99
window.removeEventListener(CONSTANT.GLOBAL.HIDE, this.globalHide)
1010
window.addEventListener(CONSTANT.GLOBAL.HIDE, this.globalHide, false)
@@ -18,8 +18,10 @@ export default function (target) {
1818
window.addEventListener(CONSTANT.GLOBAL.SHOW, this.globalShow, false)
1919

2020
// Resize
21-
window.removeEventListener('resize', this.onWindowResize)
22-
window.addEventListener('resize', this.onWindowResize, false)
21+
if (resizeHide) {
22+
window.removeEventListener('resize', this.onWindowResize)
23+
window.addEventListener('resize', this.onWindowResize, false)
24+
}
2325
}
2426

2527
target.prototype.unbindWindowEvents = function () {

src/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ class ReactTooltip extends Component {
4444
afterShow: PropTypes.func,
4545
afterHide: PropTypes.func,
4646
disable: PropTypes.bool,
47-
scrollHide: PropTypes.bool
48-
}
47+
scrollHide: PropTypes.bool,
48+
resizeHide: PropTypes.bool
49+
};
50+
51+
static defaultProps = {
52+
resizeHide: true
53+
};
4954

5055
constructor (props) {
5156
super(props)
@@ -96,7 +101,7 @@ class ReactTooltip extends Component {
96101
componentDidMount () {
97102
this.setStyleHeader() // Set the style to the <link>
98103
this.bindListener() // Bind listener for tooltip
99-
this.bindWindowEvents() // Bind global event for static method
104+
this.bindWindowEvents(this.props.resizeHide) // Bind global event for static method
100105
}
101106

102107
componentWillReceiveProps (props) {

0 commit comments

Comments
 (0)