Skip to content

Commit 3041cda

Browse files
authored
fix(material/tooltip): avoid problem when triggers hide animation for not visible tooltip (#24652)
Fixes a bug in Angular Material `tooltip` when `mat-tooltip-hide` class trigger animation for not visible tooltip. Fixes #24614
1 parent 9ac264f commit 3041cda

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/material/tooltip/tooltip.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,8 +1018,22 @@ export abstract class _TooltipComponentBase implements OnDestroy {
10181018
const tooltip = this._tooltip.nativeElement;
10191019
const showClass = this._showAnimation;
10201020
const hideClass = this._hideAnimation;
1021-
tooltip.classList.remove(isVisible ? hideClass : showClass);
1022-
tooltip.classList.add(isVisible ? showClass : hideClass);
1021+
1022+
if (isVisible) {
1023+
tooltip.classList.remove(hideClass);
1024+
tooltip.classList.add(showClass);
1025+
}
1026+
1027+
if (!isVisible) {
1028+
// It's avoids the problem when `mat-tooltip-hide` triggers the animation of
1029+
// a tooltip that has not been shown yet.
1030+
if (tooltip.classList.contains(showClass)) {
1031+
tooltip.classList.add(hideClass);
1032+
}
1033+
1034+
tooltip.classList.remove(showClass);
1035+
}
1036+
10231037
this._isVisible = isVisible;
10241038

10251039
// It's common for internal apps to disable animations using `* { animation: none !important }`

0 commit comments

Comments
 (0)