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 Jan 3, 2022
1 parent 03485cd commit 136cacf
Show file tree
Hide file tree
Showing 12 changed files with 376 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ 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';

/**
* 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]="_animationMode === 'NoopAnimations'"
[class.mdc-tooltip--multiline]="_isMultiline">
<div class="mdc-tooltip__surface mdc-tooltip__surface-animation">{{message}}</div>
</div>
42 changes: 42 additions & 0 deletions src/material-experimental/mdc-tooltip/tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,46 @@
// depending on the state of the overlay. For tooltips the overlay panel should never enable
// pointer events. To overwrite the inline CSS from the overlay reference `!important` is needed.
pointer-events: none !important;

opacity: 0;
transform: scale(0.8);

// Use a very short animation if animations are disabled so the `animationend` event still fires.
&._mat-animation-noopable {
animation-duration: 1ms;
}
}

// 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 136cacf

Please sign in to comment.