Skip to content

Commit 6526277

Browse files
authored
fix(material/tooltip): animation not cancelled when mouseleave goes through 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.
1 parent 19d0b36 commit 6526277

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/material/tooltip/tooltip.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ export abstract class _MatTooltipBase<T extends _TooltipComponentBase>
409409
/** Shows the tooltip after the delay in ms, defaults to tooltip-delay-show or 0ms if no input */
410410
show(delay: number = this.showDelay, origin?: {x: number; y: number}): void {
411411
if (this.disabled || !this.message || this._isTooltipVisible()) {
412-
this._tooltipInstance?._cancelPendingHide();
412+
this._tooltipInstance?._cancelPendingAnimations();
413413
return;
414414
}
415415

@@ -437,6 +437,7 @@ export abstract class _MatTooltipBase<T extends _TooltipComponentBase>
437437
if (instance.isVisible()) {
438438
instance.hide(delay);
439439
} else {
440+
instance._cancelPendingAnimations();
440441
this._detach();
441442
}
442443
}
@@ -987,8 +988,7 @@ export abstract class _TooltipComponentBase implements OnDestroy {
987988
}
988989

989990
ngOnDestroy() {
990-
clearTimeout(this._showTimeoutId);
991-
clearTimeout(this._hideTimeoutId);
991+
this._cancelPendingAnimations();
992992
this._onHide.complete();
993993
this._triggerElement = null!;
994994
}
@@ -1015,7 +1015,11 @@ export abstract class _TooltipComponentBase implements OnDestroy {
10151015

10161016
_handleMouseLeave({relatedTarget}: MouseEvent) {
10171017
if (!relatedTarget || !this._triggerElement.contains(relatedTarget as Node)) {
1018-
this.hide(this._mouseLeaveHideDelay);
1018+
if (this.isVisible()) {
1019+
this.hide(this._mouseLeaveHideDelay);
1020+
} else {
1021+
this._finalizeAnimation(false);
1022+
}
10191023
}
10201024
}
10211025

@@ -1033,10 +1037,11 @@ export abstract class _TooltipComponentBase implements OnDestroy {
10331037
}
10341038
}
10351039

1036-
/** Cancels any pending hiding sequences. */
1037-
_cancelPendingHide() {
1040+
/** Cancels any pending animation sequences. */
1041+
_cancelPendingAnimations() {
1042+
clearTimeout(this._showTimeoutId);
10381043
clearTimeout(this._hideTimeoutId);
1039-
this._hideTimeoutId = undefined;
1044+
this._showTimeoutId = this._hideTimeoutId = undefined;
10401045
}
10411046

10421047
/** Handles the cleanup after an animation has finished. */

tools/public_api_guard/material/tooltip.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export class TooltipComponent extends _TooltipComponentBase {
188188
export abstract class _TooltipComponentBase implements OnDestroy {
189189
constructor(_changeDetectorRef: ChangeDetectorRef, animationMode?: string);
190190
afterHidden(): Observable<void>;
191-
_cancelPendingHide(): void;
191+
_cancelPendingAnimations(): void;
192192
_handleAnimationEnd({ animationName }: AnimationEvent): void;
193193
_handleBodyInteraction(): void;
194194
// (undocumented)

0 commit comments

Comments
 (0)