Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(src/index.js): Overwrite delayHide on scroll #504

Merged
merged 1 commit into from
Sep 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class ReactTooltip extends React.Component {
'showTooltip',
'updateTooltip',
'hideTooltip',
'hideTooltipOnScroll',
'getTooltipContent',
'globalRebuild',
'globalShow',
Expand Down Expand Up @@ -425,8 +426,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 @@ -463,17 +466,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