components: tooltip: buggy when deployed as an Angular Element
What is the expected behavior?
That tooltips are not buggy.
What is the current behavior?
Tooltips are buggy.
What are the steps to reproduce?
app.module.ts
import { MatTooltipModule } from '@angular/material/tooltip';
somecomponent.component.html
<button mat-button class="button" (click)="openDialog()" matTooltip="Åpne" aria-label="Åpne"> ÅPNE</button>
And then deploy the whole project as an Angular Element.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Angular CLI: 7.3.6 Node: 10.15.2 OS: win32 x64 Angular: 7.2.10 @angular/material 7.3.5 typescript 3.1.1 Chrome Version 73.0.3683.86 (Official Build) (64-bit)
Is there anything else we should know?
Every time i hover on the button, a small grey “blob” is added to a “row” under the address-field in my browser.
When i click the button, a “tick()” is triggered (because angular elements needs that without ngZone) and the row of grey blobs is replaced with the tooltip. It’s in the wrong spot, but it’s there. I suspect this has something to do with how “Angular Elements” work? Since the grey blobs were only “converted” to the tooltip after a “tick()”?
@levgaas posted the same issue a year ago, but did not specify how he managed to fix it: https://github.com/angular/material2/issues/11361
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 2
- Comments: 24 (4 by maintainers)
Is there any progress/solution for this problem. We are also experiencing the same isue with the tooltips.
Just in case anyone else has problems with this, we ended up “hiding” the original tooltips in the paginator and adding our own using “pure css”. It’s not pretty, but it works while this gets sorted out.
in styles.scss (to hide the existing tooltip):
mat-tooltip-component > .mat-tooltip { display: none; }
Added the following code to the .scss file of the component where we have the paginator: (Stole some code from this guide by @yjose: https://medium.freecodecamp.org/a-step-by-step-guide-to-making-pure-css-tooltips-3d5a3e237346)
Ok, I got it now 😃
I guess I tried stuff with
ngZone
in the wrong place!(We are using the eventBus module…)
every time that you have to use a component with two or more structural directives nested (*ngIf, *ngFor) you have to utilize the ng-template component as a wrapper, the material design library uses that in some components, and that includes the tooltips, so in order to fix your issue you have to enclose whatever component that is being rendered “dynamically” inside an ng-template (mat-tabs, anything inside a *ngFor directive, mat-tab-header, mat-tooltip, etc) , and conditionally make it visible with an *ngIf directive depending on the type of material component you are using, some would need the *ngIf others simply don’t
(note the *ngIf structural directive in the outermost component)
(note that the ng-template tag doesn’t have any structural directive)
https://blog.angular-university.io/angular-ng-template-ng-container-ngtemplateoutlet/
I created a simple example similar to what I’m doing at my real project. it’s still has that problem when I hover on the edit button in ag-grid. here’s the stackblitz code: https://stackblitz.com/github/noonhe/material-tooltip-example I don’t know if the problems is with tooltip or tabs because when I bring grids out of tabs they can show tooltips.
I had a similar issue, caused by a function running out of ng zone. My tooltip issue was similar to the description here (little boxes usually on the top left corner, but not always on top, that disappeared once I hovered/clicked elsewhere…) my guess is that calling detectChanges() actually broke that even more.
In one of my components, I listened to mat autocomplete closed event, and when it was emitted, I ran a function that emits some value. Other components and services were emitting different outputs/functions/subjects due to that emit, and all were running out of ng zone. Eventually after some time I had these tooltip (and other change detection) issues in one of my other components.
The solution was to find the first function to run out of zone (in my case it was the function I ran when mat autocomplete closed event fired), and wrap its content with zone.run() (like mentioned by guntram in https://github.com/angular/components/issues/15781#issuecomment-1095045622) As a result, all other functions that ran by other components due to that event now run inside the ng zone and all works fine now.
html (listening to closed event):
ts (wrapping with zone.run):
[in logs: “in ng zone: false”]
I am struggeling with these multiple empty
matTooltips
! It is not reliably reproducable in a simple environment with stackblitz.In one simple component, I got an
Input() boolean
, which changes - it is referenced inside an*ngIf
like that:When I remove the
*ngIf
, everything is working fine (no multiple empty tooltip overlay elements). I could not find a real solution, so to avoid using a different tooltip plugin, I use this to hide the empty tooltips:(This should be inside some global style-file, or
ViewEncapsulation.none
must be used.)After setting the empty tooltips to hidden, I thought I needed to call
changedetectorRef.detectChanges()
, because the tooltip with the correct content will have a random delay before showing up:But none of these have any effect, the tooltip just shows after a random delay, and also disappears after a random delay.
What also has completely no effect, is using
changeDetectorRef.detectChanges()
orapplicationRef.tick()
after thesomeBoolean
has been updated.I must add that we are running on Angular11, because there were some limitations using Angular12+. We are running inside PremierePro (CEP-panel), and there were severe issues with the webpack version used by the Angular12+ setups 😦
(If you are interested: check the Chromium Embedded Framework (CEF) section)
(Also, I have to say that using
ng-template
in any way (or the other suggestions in this thread or the other threads which adress this problem) did not solve it…)But this construction is not supported by angular.
I had the exact same problem in my project. I am using Angular Material in hybrid project where the Angular app bootstraps an AngularJS application. There were gray blobs on the buttons after key press or mouse click. I thought the problem was css at first because some legacy css exists in the AngularJS project but later we found out that some zone.js flags were disabled which affected the change detection cycle. Below is my updated code which works properly now.
(window as any).__Zone_disable_timers = false;
(window as any).__Zone_disable_requestAnimationFrame = false;
(window as any).__Zone_disable_XHR = false;
(window as any).__Zone_disable_on_property = false;
I just found out if your grid has more than one pages, if you go to the second page there’s no issue and it shows all tooltips correctly and even when you go back to the first page the issue is resolved and it works fine. the problem is only in the first page and until you don’t change the page.!!! I hope this new information can be useful.
Both StackBlitz links are not found for me. Thank you for posting the GitHub repo.
I don’t know what the problem is. in both stackblitz and codesandbox it gets stuck on “starting dev server” and “installing dependencies”. but it works when I run it on my computer. can you please clone my repo and run it in your computer? https://github.com/noonhe/material-tooltip-example
Is the link broken or is it just me? 😶