Skip to content

Commit 7a2d0b3

Browse files
committed
fix(src/index.js): Overwrite delayHide on scroll
Add new param `options` to `hideTooltip()` and update `addScrollListener()` to set `options` to `{ isScroll: true }`, so `hideTooltip()` can set `delayHide` to `0` if `isScroll` is `true` fix #474
1 parent 34fa8cb commit 7a2d0b3

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
@@ -100,6 +100,7 @@ class ReactTooltip extends React.Component {
100100
'showTooltip',
101101
'updateTooltip',
102102
'hideTooltip',
103+
'hideTooltipOnScroll',
103104
'getTooltipContent',
104105
'globalRebuild',
105106
'globalShow',
@@ -425,8 +426,10 @@ class ReactTooltip extends React.Component {
425426
/**
426427
* When mouse leave, hide tooltip
427428
*/
428-
hideTooltip (e, hasTarget) {
429-
const {delayHide, disable} = this.state
429+
hideTooltip (e, hasTarget, options = { isScroll: false }) {
430+
const {disable} = this.state
431+
const {isScroll} = options
432+
const delayHide = isScroll ? 0 : this.state.delayHide
430433
const {afterHide} = this.props
431434
const placeholder = this.getTooltipContent()
432435
if (!this.mount) return
@@ -463,17 +466,24 @@ class ReactTooltip extends React.Component {
463466
}
464467
}
465468

469+
/**
470+
* When scroll, hide tooltip
471+
*/
472+
hideTooltipOnScroll (event, hasTarget) {
473+
this.hideTooltip(event, hasTarget, { isScroll: true })
474+
}
475+
466476
/**
467477
* Add scroll event listener when tooltip show
468478
* automatically hide the tooltip when scrolling
469479
*/
470480
addScrollListener (currentTarget) {
471481
const isCaptureMode = this.isCapture(currentTarget)
472-
window.addEventListener('scroll', this.hideTooltip, isCaptureMode)
482+
window.addEventListener('scroll', this.hideTooltipOnScroll, isCaptureMode)
473483
}
474484

475485
removeScrollListener () {
476-
window.removeEventListener('scroll', this.hideTooltip)
486+
window.removeEventListener('scroll', this.hideTooltipOnScroll)
477487
}
478488

479489
// Calculation the position

0 commit comments

Comments
 (0)