Skip to content

Commit

Permalink
fix(material/tooltip): animation not cancelled when mouseleave goes t…
Browse files Browse the repository at this point in the history
…hrough tooltip (#25740)

We ignore `mouseleave` events that go into the tooltip which meant that some animations weren't being cancelled correctly after the fix in #25699. These changes resolve the issue by skipping all animations if the tooltip isn't fully shown yet.

Fixes #24614.
  • Loading branch information
crisbeto committed Oct 3, 2022
1 parent 19d0b36 commit 6526277
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions src/material/tooltip/tooltip.ts
Expand Up @@ -409,7 +409,7 @@ export abstract class _MatTooltipBase<T extends _TooltipComponentBase>
/** Shows the tooltip after the delay in ms, defaults to tooltip-delay-show or 0ms if no input */
show(delay: number = this.showDelay, origin?: {x: number; y: number}): void {
if (this.disabled || !this.message || this._isTooltipVisible()) {
this._tooltipInstance?._cancelPendingHide();
this._tooltipInstance?._cancelPendingAnimations();
return;
}

Expand Down Expand Up @@ -437,6 +437,7 @@ export abstract class _MatTooltipBase<T extends _TooltipComponentBase>
if (instance.isVisible()) {
instance.hide(delay);
} else {
instance._cancelPendingAnimations();
this._detach();
}
}
Expand Down Expand Up @@ -987,8 +988,7 @@ export abstract class _TooltipComponentBase implements OnDestroy {
}

ngOnDestroy() {
clearTimeout(this._showTimeoutId);
clearTimeout(this._hideTimeoutId);
this._cancelPendingAnimations();
this._onHide.complete();
this._triggerElement = null!;
}
Expand All @@ -1015,7 +1015,11 @@ export abstract class _TooltipComponentBase implements OnDestroy {

_handleMouseLeave({relatedTarget}: MouseEvent) {
if (!relatedTarget || !this._triggerElement.contains(relatedTarget as Node)) {
this.hide(this._mouseLeaveHideDelay);
if (this.isVisible()) {
this.hide(this._mouseLeaveHideDelay);
} else {
this._finalizeAnimation(false);
}
}
}

Expand All @@ -1033,10 +1037,11 @@ export abstract class _TooltipComponentBase implements OnDestroy {
}
}

/** Cancels any pending hiding sequences. */
_cancelPendingHide() {
/** Cancels any pending animation sequences. */
_cancelPendingAnimations() {
clearTimeout(this._showTimeoutId);
clearTimeout(this._hideTimeoutId);
this._hideTimeoutId = undefined;
this._showTimeoutId = this._hideTimeoutId = undefined;
}

/** Handles the cleanup after an animation has finished. */
Expand Down
2 changes: 1 addition & 1 deletion tools/public_api_guard/material/tooltip.md
Expand Up @@ -188,7 +188,7 @@ export class TooltipComponent extends _TooltipComponentBase {
export abstract class _TooltipComponentBase implements OnDestroy {
constructor(_changeDetectorRef: ChangeDetectorRef, animationMode?: string);
afterHidden(): Observable<void>;
_cancelPendingHide(): void;
_cancelPendingAnimations(): void;
_handleAnimationEnd({ animationName }: AnimationEvent): void;
_handleBodyInteraction(): void;
// (undocumented)
Expand Down

0 comments on commit 6526277

Please sign in to comment.