Skip to content

Commit 07fda17

Browse files
committed
fix(material/card): allow for elevation to be overridden
Fixes that users weren't able to override the card elevation by setting the elevation classes. Fixes #26094.
1 parent b7dc6c6 commit 07fda17

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

src/material/card/_card-theme.scss

-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@use '../core/theming/theming';
22
@use '../core/mdc-helpers/mdc-helpers';
3-
@use '../core/style/private';
43
@use '../core/typography/typography';
54
@use '@material/card/elevated-card-theme' as mdc-elevated-card-theme;
65
@use '@material/card/outlined-card-theme' as mdc-outlined-card-theme;
@@ -15,18 +14,12 @@
1514

1615
@include mdc-helpers.using-mdc-theme($config) {
1716
.mat-mdc-card {
18-
// MDC's theme has `container-elevation` and `container-shadow-color` tokens, but we can't
19-
// use them because they output under a `.mdc-card` selector whereas the rest of the theme
20-
// isn't under any selector. Even if the mixin is pulled out of the selector, it throws a
21-
// different error.
22-
@include private.private-theme-elevation(1, $config);
2317
@include mdc-elevated-card-theme.theme((
2418
container-color: mdc-theme-color.prop-value(surface),
2519
));
2620
}
2721

2822
.mat-mdc-card-outlined {
29-
@include private.private-theme-elevation(0, $config);
3023
@include mdc-outlined-card-theme.theme((
3124
outline-color: color.mix(mdc-theme-color.prop-value(on-surface),
3225
mdc-theme-color.prop-value(surface), 12%)

src/material/card/card.scss

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
@use '@material/card/elevated-card-theme' as mdc-elevated-card-theme;
44
@use '@material/card/outlined-card-theme' as mdc-outlined-card-theme;
55
@use '../core/mdc-helpers/mdc-helpers';
6+
@use '../core/style/elevation';
67

78
// TODO(jelbourn): move header and title-group styles to their own files.
89

@@ -18,6 +19,11 @@ $mat-card-default-padding: 16px !default;
1819
}
1920

2021
.mat-mdc-card {
22+
// MDC's theme has `container-elevation` and `container-shadow-color` tokens, but we can't
23+
// use them because they output under a `.mdc-card` selector whereas the rest of the theme
24+
// isn't under any selector. Even if the mixin is pulled out of the selector, it throws a
25+
// different error.
26+
box-shadow: var(--mat-mdc-elevation-override, #{elevation.private-get-elevation-shadow(1)});
2127
position: relative;
2228

2329
@include mdc-helpers.disable-mdc-fallback-declarations {
@@ -29,6 +35,8 @@ $mat-card-default-padding: 16px !default;
2935
}
3036

3137
.mat-mdc-card-outlined {
38+
--mat-mdc-elevation-override: none;
39+
3240
@include mdc-helpers.disable-mdc-fallback-declarations {
3341
@include mdc-outlined-card-theme.theme-styles((
3442
outline-color: transparent,

src/material/core/style/_elevation.scss

+12-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ $color: black !default;
3434
// Prefix for elevation-related selectors.
3535
$prefix: 'mat-elevation-z';
3636

37-
// Applies the correct css rules to an element to give it the elevation specified by $zValue.
38-
// The $zValue must be between 0 and 24.
39-
@mixin elevation($zValue, $color: $color, $opacity: null) {
37+
// Gets the box shadow value for a specific elevation.
38+
@function private-get-elevation-shadow($zValue, $color: $color, $opacity: null) {
4039
@if meta.type-of($color) == color and $opacity == null {
41-
@include mdc-elevation.elevation($zValue, $color);
40+
@return mdc-elevation.elevation-box-shadow($zValue, $color);
4241
}
4342
@else {
4443
// Copied from @material/elevation/_elevation-theme.scss#_box-shadow
@@ -53,10 +52,18 @@ $prefix: 'mat-elevation-z';
5352
#{'#{$penumbra-z-value} #{$shadow-color}'},
5453
#{$ambient-z-value} $shadow-color
5554
);
56-
@include mdc-elevation.shadow($box-shadow);
55+
@return $box-shadow;
5756
}
5857
}
5958

59+
// Applies the correct css rules to an element to give it the elevation specified by $zValue.
60+
// The $zValue must be between 0 and 24.
61+
@mixin elevation($zValue, $color: $color, $opacity: null) {
62+
$shadow: private-get-elevation-shadow($zValue, $color, $opacity);
63+
box-shadow: $shadow;
64+
--mat-mdc-elevation-override: #{$shadow};
65+
}
66+
6067
// Applies the elevation to an element in a manner that allows
6168
// consumers to override it via the Material elevation classes.
6269
@mixin overridable-elevation($zValue, $color: $color) {

0 commit comments

Comments
 (0)