Skip to content

Commit

Permalink
Merge pull request #504 from tihuan/fix-474
Browse files Browse the repository at this point in the history
fix(src/index.js): Overwrite `delayHide` on scroll
  • Loading branch information
aronhelser authored Sep 6, 2019
2 parents 545c19c + 7a2d0b3 commit 11ee685
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class ReactTooltip extends React.Component {
'showTooltip',
'updateTooltip',
'hideTooltip',
'hideTooltipOnScroll',
'getTooltipContent',
'globalRebuild',
'globalShow',
Expand Down Expand Up @@ -433,8 +434,10 @@ class ReactTooltip extends React.Component {
/**
* When mouse leave, hide tooltip
*/
hideTooltip (e, hasTarget) {
const {delayHide, disable} = this.state
hideTooltip (e, hasTarget, options = { isScroll: false }) {
const {disable} = this.state
const {isScroll} = options
const delayHide = isScroll ? 0 : this.state.delayHide
const {afterHide} = this.props
const placeholder = this.getTooltipContent()
if (!this.mount) return
Expand Down Expand Up @@ -471,17 +474,24 @@ class ReactTooltip extends React.Component {
}
}

/**
* When scroll, hide tooltip
*/
hideTooltipOnScroll (event, hasTarget) {
this.hideTooltip(event, hasTarget, { isScroll: true })
}

/**
* Add scroll event listener when tooltip show
* automatically hide the tooltip when scrolling
*/
addScrollListener (currentTarget) {
const isCaptureMode = this.isCapture(currentTarget)
window.addEventListener('scroll', this.hideTooltip, isCaptureMode)
window.addEventListener('scroll', this.hideTooltipOnScroll, isCaptureMode)
}

removeScrollListener () {
window.removeEventListener('scroll', this.hideTooltip)
window.removeEventListener('scroll', this.hideTooltipOnScroll)
}

// Calculation the position
Expand Down

0 comments on commit 11ee685

Please sign in to comment.