Skip to content

fix(tooltip): remove native event listener on component destroy #5144

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

Merged
merged 3 commits into from
Jul 7, 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
14 changes: 12 additions & 2 deletions src/lib/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ export class MdTooltip implements OnDestroy {
get _matClass() { return this.tooltipClass; }
set _matClass(v) { this.tooltipClass = v; }

private _enterListener: Function;
private _leaveListener: Function;

constructor(
private _overlay: Overlay,
private _elementRef: ElementRef,
Expand All @@ -183,8 +186,10 @@ export class MdTooltip implements OnDestroy {
// The mouse events shouldn't be bound on iOS devices, because
// they can prevent the first tap from firing its click event.
if (!_platform.IOS) {
_renderer.listen(_elementRef.nativeElement, 'mouseenter', () => this.show());
_renderer.listen(_elementRef.nativeElement, 'mouseleave', () => this.hide());
this._enterListener =
_renderer.listen(_elementRef.nativeElement, 'mouseenter', () => this.show());
this._leaveListener =
_renderer.listen(_elementRef.nativeElement, 'mouseleave', () => this.hide());
}
}

Expand All @@ -195,6 +200,11 @@ export class MdTooltip implements OnDestroy {
if (this._tooltipInstance) {
this._disposeTooltip();
}
// Clean up the event listeners set in the constructor
if (!this._platform.IOS) {
this._enterListener();
this._leaveListener();
}
}

/** Shows the tooltip after the delay in ms, defaults to tooltip-delay-show or 0ms if no input */
Expand Down