From 7cc12039a1646cc19b063f80382c661a6d7ef2ec Mon Sep 17 00:00:00 2001 From: mjeffrie <46824118+mjeffrie@users.noreply.github.com> Date: Wed, 6 May 2020 22:26:33 -0500 Subject: [PATCH] fix: release event listners (#534) --- src/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 9790198f..1acce0e8 100755 --- a/src/index.js +++ b/src/index.js @@ -169,7 +169,7 @@ class ReactTooltip extends React.Component { this.clearTimer(); this.unbindListener(); - this.removeScrollListener(); + this.removeScrollListener(this.state.currentTarget); this.unbindWindowEvents(); } @@ -573,7 +573,7 @@ class ReactTooltip extends React.Component { this.removeListenerForTooltipExit(); this.setState({ show: false }, () => { - this.removeScrollListener(); + this.removeScrollListener(this.state.currentTarget); if (isVisible && afterHide) { afterHide(e); } @@ -604,8 +604,9 @@ class ReactTooltip extends React.Component { window.addEventListener("scroll", this.hideTooltipOnScroll, isCaptureMode); } - removeScrollListener() { - window.removeEventListener("scroll", this.hideTooltipOnScroll); + removeScrollListener(currentTarget) { + const isCaptureMode = this.isCapture(currentTarget); + window.removeEventListener("scroll", this.hideTooltipOnScroll, isCaptureMode); } // Calculation the position