Skip to content

Commit

Permalink
fix(material/tooltip): decouple removal logic from change detection
Browse files Browse the repository at this point in the history
Currently the logic in the tooltip that removes it from the DOM is run either if the trigger
is destroyed or the exit animation has finished. The problem is that if the trigger is
detached from change detection, but hasn't been destroyed, the exit animation will
never run and the element won't be cleaned up. These changes switch to using CSS
animations and manipulating the DOM node directly to trigger the animation.

Fixes #19365.
  • Loading branch information
crisbeto committed Mar 5, 2022
1 parent e89bce8 commit 27cf676
Show file tree
Hide file tree
Showing 13 changed files with 418 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export class MatTooltipHarness extends _MatTooltipHarnessBase {
protected _optionalPanel =
this.documentRootLocatorFactory().locatorForOptional('.mat-mdc-tooltip');
static hostSelector = '.mat-mdc-tooltip-trigger';
protected _hiddenClass = 'mat-mdc-tooltip-hide';
protected _showAnimationName = 'mat-mdc-tooltip-show';
protected _hideAnimationName = 'mat-mdc-tooltip-hide';

/**
* Gets a `HarnessPredicate` that can be used to search
Expand Down
7 changes: 3 additions & 4 deletions src/material-experimental/mdc-tooltip/tooltip.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<div
#tooltip
class="mdc-tooltip mdc-tooltip--shown mat-mdc-tooltip"
[ngClass]="tooltipClass"
[class.mdc-tooltip--multiline]="_isMultiline"
[@state]="_visibility"
(@state.start)="_animationStart()"
(@state.done)="_animationDone($event)">
[class._mat-animation-noopable]="_animationsDisabled"
[class.mdc-tooltip--multiline]="_isMultiline">
<div class="mdc-tooltip__surface mdc-tooltip__surface-animation">{{message}}</div>
</div>
40 changes: 40 additions & 0 deletions src/material-experimental/mdc-tooltip/tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.mat-mdc-tooltip {
// We don't use MDC's positioning so this has to be relative.
position: relative;
transform: scale(0);

// Increases the area of the tooltip so the user's pointer can go from the trigger directly to it.
&::before {
Expand All @@ -18,8 +19,47 @@
z-index: -1;
position: absolute;
}

&._mat-animation-noopable {
animation: none;
transform: none;
}
}

.mat-mdc-tooltip-panel-non-interactive {
pointer-events: none;
}

// TODO(crisbeto): we may be able to use MDC directly for these animations.

@keyframes mat-mdc-tooltip-show {
0% {
opacity: 0;
transform: scale(0.8);
}

100% {
opacity: 1;
transform: scale(1);
}
}

@keyframes mat-mdc-tooltip-hide {
0% {
opacity: 1;
transform: scale(1);
}

100% {
opacity: 0;
transform: scale(0.8);
}
}

.mat-mdc-tooltip-show {
animation: mat-mdc-tooltip-show 150ms cubic-bezier(0, 0, 0.2, 1) forwards;
}

.mat-mdc-tooltip-hide {
animation: mat-mdc-tooltip-hide 75ms cubic-bezier(0.4, 0, 1, 1) forwards;
}
Loading

0 comments on commit 27cf676

Please sign in to comment.