Skip to content

Commit 11ee685

Browse files
authored
Merge pull request #504 from tihuan/fix-474
fix(src/index.js): Overwrite `delayHide` on scroll
2 parents 545c19c + 7a2d0b3 commit 11ee685

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/index.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class ReactTooltip extends React.Component {
101101
'showTooltip',
102102
'updateTooltip',
103103
'hideTooltip',
104+
'hideTooltipOnScroll',
104105
'getTooltipContent',
105106
'globalRebuild',
106107
'globalShow',
@@ -433,8 +434,10 @@ class ReactTooltip extends React.Component {
433434
/**
434435
* When mouse leave, hide tooltip
435436
*/
436-
hideTooltip (e, hasTarget) {
437-
const {delayHide, disable} = this.state
437+
hideTooltip (e, hasTarget, options = { isScroll: false }) {
438+
const {disable} = this.state
439+
const {isScroll} = options
440+
const delayHide = isScroll ? 0 : this.state.delayHide
438441
const {afterHide} = this.props
439442
const placeholder = this.getTooltipContent()
440443
if (!this.mount) return
@@ -471,17 +474,24 @@ class ReactTooltip extends React.Component {
471474
}
472475
}
473476

477+
/**
478+
* When scroll, hide tooltip
479+
*/
480+
hideTooltipOnScroll (event, hasTarget) {
481+
this.hideTooltip(event, hasTarget, { isScroll: true })
482+
}
483+
474484
/**
475485
* Add scroll event listener when tooltip show
476486
* automatically hide the tooltip when scrolling
477487
*/
478488
addScrollListener (currentTarget) {
479489
const isCaptureMode = this.isCapture(currentTarget)
480-
window.addEventListener('scroll', this.hideTooltip, isCaptureMode)
490+
window.addEventListener('scroll', this.hideTooltipOnScroll, isCaptureMode)
481491
}
482492

483493
removeScrollListener () {
484-
window.removeEventListener('scroll', this.hideTooltip)
494+
window.removeEventListener('scroll', this.hideTooltipOnScroll)
485495
}
486496

487497
// Calculation the position

0 commit comments

Comments
 (0)