Skip to content

Commit 0f2ec70

Browse files
volvachevwagnermaciel
authored andcommitted
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 (cherry picked from commit 3041cda)
1 parent 1381cc0 commit 0f2ec70

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
@@ -989,8 +989,22 @@ export abstract class _TooltipComponentBase implements OnDestroy {
989989
const tooltip = this._tooltip.nativeElement;
990990
const showClass = this._showAnimation;
991991
const hideClass = this._hideAnimation;
992-
tooltip.classList.remove(isVisible ? hideClass : showClass);
993-
tooltip.classList.add(isVisible ? showClass : hideClass);
992+
993+
if (isVisible) {
994+
tooltip.classList.remove(hideClass);
995+
tooltip.classList.add(showClass);
996+
}
997+
998+
if (!isVisible) {
999+
// It's avoids the problem when `mat-tooltip-hide` triggers the animation of
1000+
// a tooltip that has not been shown yet.
1001+
if (tooltip.classList.contains(showClass)) {
1002+
tooltip.classList.add(hideClass);
1003+
}
1004+
1005+
tooltip.classList.remove(showClass);
1006+
}
1007+
9941008
this._isVisible = isVisible;
9951009

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

0 commit comments

Comments
 (0)