Skip to content

fix(material/tooltip): decouple removal logic from change detection - #19432

Merged
crisbeto merged 2 commits into
angular:masterfrom
crisbeto:19365/tooltip-animations-refactor
Mar 6, 2022
Merged

fix(material/tooltip): decouple removal logic from change detection#19432
crisbeto merged 2 commits into
angular:masterfrom
crisbeto:19365/tooltip-animations-refactor

Conversation

@crisbeto

Copy link
Copy Markdown
Member

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.

@crisbetocrisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note G This is is related to a Google internal issue target: patch This PR is targeted for the next patch release labels May 24, 2020
@googlebotgooglebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label May 24, 2020
@crisbeto

Copy link
Copy Markdown
MemberAuthor

Caretaker note: these changes have the potential to break people's tests. We should determine whether to move forward, based on how many targets it breaks.

@crisbeto
crisbetoforce-pushed the 19365/tooltip-animations-refactor branch 2 times, most recently from 2f8fdae to 1be7eebCompareMay 24, 2020 12:12
Comment threadsrc/material/tooltip/tooltip.scss Outdated
opacity: 0;
transform: scale(0);

// Use a very short animation if animations are disabled so the `animationend` event still fires.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can check with a presubmit, but this feels like it could cause some issues where people are expecting synchronous behavior

Comment threadsrc/material/tooltip/tooltip.ts Outdated
Comment threadsrc/material/tooltip/tooltip.ts Outdated
* @param delay Amount of milliseconds to the delay showing the tooltip.
*/
show(delay: number): void {
show(delay: number, isUserInteraction?: boolean): void {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this is a breaking change since we export TooltipComponent in the public API (probably unintentionally)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's breaking since the new parameter is optional.

@jelbournjelbourn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jelbourn

Copy link
Copy Markdown
Contributor

Looks like it needs a rebase to presubmit

@crisbeto
crisbetoforce-pushed the 19365/tooltip-animations-refactor branch from 1be7eeb to f31088bCompareJune 9, 2020 15:22
@crisbetocrisbeto added action: merge The PR is ready for merge by the caretaker and removed needs rebase labels Jun 9, 2020
@crisbeto
crisbetoforce-pushed the 19365/tooltip-animations-refactor branch from f31088b to 27181b3CompareJune 13, 2020 09:58
@crisbeto
crisbetoforce-pushed the 19365/tooltip-animations-refactor branch from 27181b3 to b532858CompareJuly 3, 2020 21:05
@mmalerbammalerba removed the lgtm label Jul 31, 2020
@crisbeto
crisbetoforce-pushed the 19365/tooltip-animations-refactor branch from b532858 to 9f1ab9eCompareAugust 1, 2020 12:00
@crisbeto
crisbetoforce-pushed the 19365/tooltip-animations-refactor branch from 9f1ab9e to c28838eCompareAugust 16, 2020 07:17
@crisbeto

Copy link
Copy Markdown
MemberAuthor

I pushed one more change to help address the concerns from #15990 by binding the internal animationend event outside the NgZone. I'm also bumping it to a P2, because this has come up a few times while triaging issues.

@crisbetocrisbeto added P2 The issue is important to a large percentage of users, with a workaround and removed P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels Aug 16, 2020
@mmalerba

Copy link
Copy Markdown
Contributor

FYI this has 24 failing targets, it would be possible to get in, but would take some effort

@crisbeto
crisbetoforce-pushed the 19365/tooltip-animations-refactor branch 2 times, most recently from a9182a7 to a12d729CompareJune 20, 2021 12:18
@andrewseguinandrewseguin added needs rebase and removed cla: yes PR author has agreed to Google's Contributor License Agreement labels Dec 28, 2021
@crisbeto
crisbetoforce-pushed the 19365/tooltip-animations-refactor branch from a12d729 to 136cacfCompareJanuary 3, 2022 09:40
@mmalerba

Copy link
Copy Markdown
Contributor

It seems that there's something not being properly flushed when using the harness. There's a test that looks roughly like this:

 const tooltip1 = await getHarness(MatTooltipHarness.with({selector: 'tt1'}));
await (await tooltip1.host()).hover();
expect(await tooltip1.isOpen()).toEqual(true);
await (await tooltip1.host()).mouseAway();
const tooltip2 = await getHarness(MatTooltipHarness.with({selector: 'tt2'}));
await (await tooltip2.host()).hover();
expect(await tooltip2.isOpen()).toEqual(true);
await (await tooltip2.host()).mouseAway();

For the second tooltip the isOpen check fails, if I comment out the tooltip1 stuff then it passes

@mmalerbammalerba removed the action: merge The PR is ready for merge by the caretaker label Jan 20, 2022
@crisbeto
crisbetoforce-pushed the 19365/tooltip-animations-refactor branch from 136cacf to 46e4e9aCompareMarch 5, 2022 11:01
@crisbetocrisbeto added the action: merge The PR is ready for merge by the caretaker label Mar 5, 2022
@crisbeto

Copy link
Copy Markdown
MemberAuthor

I've rebased and added some logic to the test harnesses to simulate the animationend events.

@crisbeto
crisbetoforce-pushed the 19365/tooltip-animations-refactor branch 4 times, most recently from 27cf676 to da99bbdCompareMarch 5, 2022 15:33
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.
Fixesangular#19365.
@crisbeto
crisbetoforce-pushed the 19365/tooltip-animations-refactor branch 4 times, most recently from 851cdfe to 01eacdcCompareMarch 6, 2022 09:34
@crisbeto
crisbetoforce-pushed the 19365/tooltip-animations-refactor branch from 01eacdc to fb516c0CompareMarch 6, 2022 10:16
@crisbeto
crisbeto merged commit a5ab8e9 into angular:masterMar 6, 2022
crisbeto added a commit that referenced this pull request Mar 6, 2022
…19432)
* fix(material/tooltip): decouple removal logic from change detection
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.
* fixup! fix(material/tooltip): decouple removal logic from change detection
(cherry picked from commit a5ab8e9)
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Mar 18, 2022
This PR contains the following updates:
| Package | Type | Update | Change |
|---|---|---|---|
| [@angular/cdk](https://github.com/angular/components) | dependencies | patch | [`13.2.5` -> `13.2.6`](https://renovatebot.com/diffs/npm/@angular%2fcdk/13.2.5/13.2.6) |
| [@angular/material](https://github.com/angular/components) | dependencies | patch | [`13.2.5` -> `13.2.6`](https://renovatebot.com/diffs/npm/@angular%2fmaterial/13.2.5/13.2.6) |
---
### Release Notes
<details>
<summary>angular/components</summary>
### [`v13.2.6`](https://github.com/angular/components/blob/HEAD/CHANGELOG.md#&#8203;1326-suede-spaghetti-2022-03-09)
[Compare Source](angular/components@13.2.5...13.2.6)
##### cdk
| Commit | Type | Description |
| -- | -- | -- |
| [39929a815d](angular/components@39929a8) | fix | **overlay:** backdrop timeouts not being cleared in some cases ([#&#8203;23972](angular/components#23972)) |
| [2f2b0c7cf4](angular/components@2f2b0c7) | fix | **testing:** dispatch mouseover and mouseout events in UnitTestElement ([#&#8203;24490](angular/components#24490)) |
| [edca54f2d0](angular/components@edca54f) | fix | **testing:** require at least one argument for locator functions ([#&#8203;23619](angular/components#23619)) |
##### material
| Commit | Type | Description |
| -- | -- | -- |
| [c4993ac171](angular/components@c4993ac) | fix | **button:** avoid setting a tabindex on all link buttons ([#&#8203;22901](angular/components#22901)) |
| [c47d30e0e5](angular/components@c47d30e) | fix | **dialog:** don't wait for animation before moving focus ([#&#8203;24121](angular/components#24121)) |
| [70b8248568](angular/components@70b8248) | fix | **expansion:** able to tab into descendants with visibility while closed ([#&#8203;24045](angular/components#24045)) |
| [d22d73ab8d](angular/components@d22d73a) | fix | **select:** disabled state out of sync when swapping form group with a disabled one ([#&#8203;17872](angular/components#17872)) |
| [911d6b71d4](angular/components@911d6b7) | fix | **slide-toggle:** clear name from host node ([#&#8203;15505](angular/components#15505)) |
| [4b5363d160](angular/components@4b5363d) | fix | **tooltip:** decouple removal logic from change detection ([#&#8203;19432](angular/components#19432)) |
##### material-experimental
| Commit | Type | Description |
| -- | -- | -- |
| [8414646d79](angular/components@8414646) | fix | **mdc-card:** remove extra margin if header doesn't have an avatar ([#&#8203;19072](angular/components#19072)) |
| [f66486dc5b](angular/components@f66486d) | fix | **mdc-slider:** fix a few null pointer exceptions ([#&#8203;23659](angular/components#23659)) |
##### multiple
| Commit | Type | Description |
| -- | -- | -- |
| [6ee0089ce6](angular/components@6ee0089) | fix | don't block child component animations on open ([#&#8203;24529](angular/components#24529)) |
#### Special Thanks
Andrew Seguin, Jeri Peier, Kristiyan Kostadinov and Paul Gschwendtner
<!-- CHANGELOG SPLIT MARKER -->
</details>
---
### Configuration
📅 **Schedule**: At any time (no schedule defined).
🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.
♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.
---
- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.
---
This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1214
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
forsti0506 pushed a commit to forsti0506/components that referenced this pull request Apr 3, 2022
…ngular#19432)
* fix(material/tooltip): decouple removal logic from change detection
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.
Fixesangular#19365.
* fixup! fix(material/tooltip): decouple removal logic from change detection
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-botangular-automatic-lock-botBot locked and limited conversation to collaborators Apr 6, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: mergeThe PR is ready for merge by the caretakerGThis is is related to a Google internal issuemerge: caretaker noteAlert the caretaker performing the merge to check the PR for an out of normal action needed or noteP2The issue is important to a large percentage of users, with a workaroundtarget: patchThis PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(MatTooltip): MatTooltip not work well with cdk-virtual-scroll-viewport

5 participants

@crisbeto@jelbourn@mmalerba@andrewseguin@googlebot