components icon indicating copy to clipboard operation
components copied to clipboard

Not able to change the background color of the mat tooltip modal using the matTooltipClass class

Open SantoshNayak opened this issue 2 years ago • 7 comments

          The [Material Design guidelines](https://material.io/guidelines/components/tooltips.html#tooltips-tooltips-desktop) goes against what you are trying to do since it specifies only one color can be used, but it can be possible. Just use the `matTooltipClass` input:
<span matTooltip="Tooltip!" matTooltipClass="primary-tooltip">Content</span>
.primary-tooltip {
    background-color: #3F51B5;
}

Originally posted by @EdricChan03 in https://github.com/angular/components/issues/8296#issuecomment-342753938

SantoshNayak avatar May 24 '23 06:05 SantoshNayak

Any updates on this?

magentaRE avatar Jul 21 '23 11:07 magentaRE

Half a year open ticket without any care. That is sad as this was surely a breaking change in one of the previous releases.

Applying custom style via matTooltipClass used to work before v16. I'ved realized in one of my projects on v16 that it is broken and doesn't work even in stackblitz in v17

GeorgeKnap avatar Dec 12 '23 17:12 GeorgeKnap

Does anyone know if the name of the property changed?

servicomf5 avatar Jan 24 '24 02:01 servicomf5

same issue with v17. Any updates ?

detollenaere avatar May 31 '24 09:05 detollenaere

Works with v18 // Global Modification

.mat-mdc-tooltip {
    font-size: 0.75rem;
}

// Custom Modification

 .your-css .mdc-tooltip__surface {
    color: black;
    background: white;
  }

angelsaga avatar Jun 27 '24 09:06 angelsaga

With Angular 18, I was able to use a small spin from angelsaga's approach in my component.scss to style the colors on the matToolTip:

.mdc-tooltip__surface { color: black !important; background-color: white !important; }

The !important declaration was indeed necessary. Also, my component.ts has the encapsulation set to none.

encapsulation: ViewEncapsulation.None

KenPlat avatar Aug 01 '24 20:08 KenPlat

As suggested by KenPlat, I used the same approach, and it works in Angular 17 as well:

  1. Add encapsulation: ViewEncapsulation.None to the component decorator.
  2. Add the original matTooltipClass to the element.
  3. Set the expected styles and add !important.
.tooltip-danger .mdc-tooltip__surface {
  font-size: 14px !important;
  color: red !important;
  background-color: white !important;
}

This can be used normally.

dackdada016 avatar Aug 07 '24 09:08 dackdada016