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(material/tooltip): animation not cancelled when mouseleave goes through tooltip #25740

Merged
merged 1 commit into from Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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