components icon indicating copy to clipboard operation
components copied to clipboard

bug(mat-card): mat-elevation-zx no longer working for mat-card after upgrade to version 15

Open ChristopherSnay opened this issue 2 years ago • 36 comments

Is this a regression?

  • [X] Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

14

Description

I have some mat-cards with specific elevations set, like for example: class=mat-elevation-z4 After the upgrade from 14 to 15, the cards are no longer affected by any mat-elevation classes I add.

Reproduction

Steps to reproduce:

  1. in a template, use <mat-card class="mat-elevation-z8">test</mat-card>
  2. notice that the elevation helper class has no effect on the mat-card's elevation

Expected Behavior

Expecting the mat-elevation-z_x_ classes to modify the mat-card's elevation.

Actual Behavior

elevation is not affected by adding, for example, class="mat-elevation-z8"

Environment

  • Angular: 15.0.0
  • CDK/Material: 15.0.0
  • Browser(s): Edge/Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows

ChristopherSnay avatar Nov 26 '22 19:11 ChristopherSnay

confirmed: https://stackblitz.com/edit/angular-v7wcjs?file=src%2Fmain.ts

notice, that @includes with elevation helpers does not work on mat-card, too:

mat-card {
  @include mat.elevation(8);
}

RobinKamps avatar Nov 27 '22 08:11 RobinKamps

I spent some time trying to fix this in #26098, but it ended up breaking too many internal apps. For future reference, here's what I tried:

  1. Switching the card theme to use the private-theme-overridable-elevation mixin instead of private-theme-elevation. This is the correct way to fix it, but it ends up increasing the specificity too much which was breaking some style overrides.
  2. Switching the box-shadow to a CSS variable and setting variable in the mat-elevation-z* classes. This reduces the specificity, but appears not to be enough for some cases.
  3. Using the mat-card tag selector to set the box-shadow instead of .mat-mdc-card. This seems to reduce the specificity a bit too much and is against our CSS selector guidelines.

crisbeto avatar Nov 29 '22 07:11 crisbeto

Hi,

Same problem with mat-elevation-z* classes and elevation helpers: no elevation anymore. By the way, i don't know if this is done on purpose, but it seems running "mdc-migration" command in not listed on angular material 14 -> 15 migration guide.

FI class styles are applied, but they are immediately preceeded by mdc styles. So basicaly they are ignored

hhsissi avatar Dec 04 '22 22:12 hhsissi

By the way, i don't know if this is done on purpose, but it seems running "mdc-migration" command in not listed on angular material 14 -> 15 migration guide.

It adds the step if you check the "I use Angular material" checkbox. The migration tool is mentioned in the Read Further link

In Angular Material v15, many of the components have been refactored to be based on the official Material Design Components for Web (MDC). This change affected the DOM and CSS classes of many components. Read further

ChristopherSnay avatar Dec 05 '22 17:12 ChristopherSnay

Will this be fixed in v15.1.0 or do we have to employ our workarounds for now?

emonney avatar Jan 07 '23 19:01 emonney

It won't be fixed for 15.1.0.

crisbeto avatar Jan 07 '23 22:01 crisbeto

I noticed that the mdc-migration schematic is changing cards to use outline for appearance, when they didn't originally use it. Was that done intentionally as a stopgap because of the elevation styles not working? If not, I can open a separate issue for that.

michaelfaith avatar Jan 18 '23 23:01 michaelfaith

This is working. mat-card-content class="mat-elevation-z8"

Use mat-card-content tag.

just4td avatar Jan 24 '23 10:01 just4td

That doesn't really give desired results... (should be the whole card)

image

michaelfaith avatar Jan 24 '23 10:01 michaelfaith

sounds a bit crazy, but you need to move all your mat-card to the outer content;

mat-card
  mat-card-content class=" .. elevation.."
    mat-card (the one that u want)

just4td avatar Jan 24 '23 11:01 just4td

Oof. I mean, that's good to know as a workaround, but that's not really an acceptable fix.

michaelfaith avatar Jan 24 '23 11:01 michaelfaith

u got it, it is a crazy workaround, until someone in google figured out a fix.

just4td avatar Jan 24 '23 12:01 just4td

Any news on this, it has been opened for more than 2 months. I would rather not implement a workaround.

yannickcare avatar Feb 03 '23 08:02 yannickcare

Still not working "@angular/material": "^15.2.3",

dnespola avatar Mar 23 '23 12:03 dnespola

Any updates on this?

kibetmasi avatar Mar 26 '23 10:03 kibetmasi

Adding these lines in global-css worked for me (workaround)

.mat-mdc-card.mat-elevation-z6 {
  @include mat.elevation(6);
}

.mat-mdc-card.mat-elevation-z8 {
  @include mat.elevation(8);
}

.mat-mdc-card.mat-elevation-z10 {
  @include mat.elevation(10);
}

// add more mat-elevations that are needed...

Version: @angular/material: 15.2.4

simonbauer-gepardec avatar Mar 29 '23 06:03 simonbauer-gepardec

In that spirit, this should re-create all of them.

@for $i from 0 through 24 {
  .mat-mdc-card.mat-elevation-z#{$i} {
    @include mat.elevation($i);
  }
}

michaelfaith avatar Mar 30 '23 12:03 michaelfaith

Try to just grow the height of mat-card, works for me the elevation.

InsaneProgZ avatar Apr 11 '23 00:04 InsaneProgZ

Try to just grow the height of mat-card, works for me the elevation.

What does this mean?

ChristopherSnay avatar Apr 11 '23 13:04 ChristopherSnay

I have this issue, with same version, but for some reason the height of mat-card box was the exactly size of card, and for this reason looks like mat-elevation-zx doesn't work, if you grow the height the mat-elevation-zx appear correctly. Sorry I don't speak english very well, do you understand?

InsaneProgZ avatar Apr 11 '23 13:04 InsaneProgZ

Same for mat-menu. The fix from @simonbauer-gepardec works:

@for $i from 0 through 24 {
  .mat-mdc-menu-panel.mat-elevation-z#{$i} {
    @include mat.elevation($i);
  }
}

develmood avatar Apr 25 '23 22:04 develmood

I am using Angular Material ^15.2.6, and I do have an extra class called mat-mdc-elevation-specific added automatically to the card. So a workaround can be that you add this class to the mat-card as well (gives specificity boost :)

<mat-card class="mat-mdc-elevation-specific mat-elevation-z4">
...

A workaround until better comes up.

Gyorgy-Szy avatar May 02 '23 09:05 Gyorgy-Szy

This is working. mat-card-content class="mat-elevation-z8"

Use mat-card-content tag.

WORKS! THANK YOU SO MUCH!

AnnaMakos avatar May 10 '23 19:05 AnnaMakos

Doesnt work in 16.0.1

Dzivo avatar May 23 '23 16:05 Dzivo

Also running into this issue. From what I can tell, .mat-elevation-z* is being overridden by .mat-mdc-card which is pulling from the theme below the elevation style. This seems like a pretty obvious oversight in how styling order is applied.

CSS classes are posted in order.

.mat-mdc-card {
    ...
    box-shadow: var(--mdc-elevated-card-container-elevation);
  ...
}

**What I want**
<style>
.mat-elevation-z8, .mat-mdc-elevation-specific.mat-elevation-z8 {
    box-shadow: 0px 5px 5px -3px rgba(0, 0, 0, 0.2), 0px 8px 10px 1px rgba(0, 0, 0, 0.14), 0px 3px 14px 2px rgba(0, 0, 0, 0.12);
}

**What I'm getting**
.mat-mdc-card {
   ...
    --mdc-elevated-card-container-elevation: 0px 2px 1px -1px rgba(0, 0, 0, 0.2), 0px 1px 1px 0px rgba(0, 0, 0, 0.14), 0px 1px 3px 0px rgba(0, 0, 0, 0.12); 
  ...
}

The styling fix posted above works, or I could just roll my own. But this is pretty clearly not working as expected.

User00015 avatar Jun 15 '23 15:06 User00015

Adding these lines in global-css worked for me (workaround)

.mat-mdc-card.mat-elevation-z6 {
  @include mat.elevation(6);
}

.mat-mdc-card.mat-elevation-z8 {
  @include mat.elevation(8);
}

.mat-mdc-card.mat-elevation-z10 {
  @include mat.elevation(10);
}

// add more mat-elevations that are needed...

Version: @angular/material: 15.2.4

This works in angular 16 also.

We also have to add the following line on the top of style.scss file. Reference @use "@angular/material" as mat;

SBahre avatar Jul 31 '23 06:07 SBahre

Most workarounds posted here (those declaring CSS classes) aren't working for me in 15.2,9, a year after this issue was opened. Only the nested card solution seems to work with a card wrapping a card-content, wrapping another card. Something interesting though: I'm attempting to show an elevated card inside a mat-tab which is animated, as default. During the animation the card elevation is visible, it disappears as soon as the animation ends.

Maybe this can help somebody track down the issue more easily.

alandsidel avatar Nov 21 '23 20:11 alandsidel

This is still an issue in 16.2.8

kamerc avatar Feb 22 '24 17:02 kamerc

I am using Angular Material ^15.2.6, and I do have an extra class called mat-mdc-elevation-specific added automatically to the card. So a workaround can be that you add this class to the mat-card as well (gives specificity boost :)

<mat-card class="mat-mdc-elevation-specific mat-elevation-z4">
...

A workaround until better comes up.

This workaround works for mat-sidenav too with Material 17 :-)

JessyParis avatar Feb 23 '24 15:02 JessyParis

when fixed?

Deliana90 avatar Mar 14 '24 17:03 Deliana90