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(interactive hideOn mouseleave) only add listener once #44

Merged
merged 1 commit into from
Aug 26, 2017
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
10 changes: 9 additions & 1 deletion addon/components/ember-attacher-inner.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export default Component.extend({
// if a _hide() is triggered before the _show() is executed
this._delayedShow = null;

// Used to prevent memory leaks where we'd keep adding a
// mouseleave listener for interactive tooltips.
this._hasInteractiveMouseLeaveListener = false;

// The final source of truth on whether or not all _hide() or _show() actions have completed
this._isHidden = true;

Expand Down Expand Up @@ -295,7 +299,10 @@ export default Component.extend({
// attachment and not trigger the hide because the hide check was debounced
// - Ideally we would debounce with an immediate run, then instead of debouncing, we would
// queue another fire at the end of the debounce period
document.addEventListener('mousemove', this._hideIfMouseOutsideTargetOrAttachment);
if (!this._hasInteractiveMouseLeaveListener) {
this._hasInteractiveMouseLeaveListener = true;
document.addEventListener('mousemove', this._hideIfMouseOutsideTargetOrAttachment);
}
} else {
this._hideAfterDelay();
}
Expand All @@ -314,6 +321,7 @@ export default Component.extend({
// The ember-attacher-inner element is wrapped in the ember-attacher element
&& !this.element.parentNode.contains(event.target)) {
// Remove this listener before hiding the attachment
this._hasInteractiveMouseLeaveListener = false;
document.removeEventListener('mousemove', this._hideIfMouseOutsideTargetOrAttachment);

target.classList.remove('active');
Expand Down