Skip to content

Commit 48153cb

Browse files
authored
fix(material/core): reintroduce opacity in elevation mixin (#26015)
During the switch to MDC the opacity parameter to the `elevation` mixin was removed which is a breaking change. It also isn't possible to achieve the same result by providing an `rgba` color, because MDC changes the color's opacity. Fixes #26004.
1 parent 9b1f49f commit 48153cb

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/material/core/style/_elevation.scss

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,22 @@ $prefix: 'mat-elevation-z';
3636

3737
// Applies the correct css rules to an element to give it the elevation specified by $zValue.
3838
// The $zValue must be between 0 and 24.
39-
@mixin elevation($zValue, $color: $color) {
40-
@if meta.type-of($color) == color {
39+
@mixin elevation($zValue, $color: $color, $opacity: null) {
40+
@if meta.type-of($color) == color and $opacity == null {
4141
@include mdc-elevation.elevation($zValue, $color);
4242
}
4343
@else {
4444
// Copied from @material/elevation/_elevation-theme.scss#_box-shadow
4545
// TODO(mmalerba): Add support for graceful handling of CSS var color to MDC.
46+
$shadow-color:
47+
if(meta.type-of($color) == color and $opacity != null, rgba($color, $opacity), $color);
4648
$umbra-z-value: map.get(mdc-elevation.$umbra-map, $zValue);
4749
$penumbra-z-value: map.get(mdc-elevation.$penumbra-map, $zValue);
4850
$ambient-z-value: map.get(mdc-elevation.$ambient-map, $zValue);
4951
$box-shadow: (
50-
#{'#{$umbra-z-value} #{$color}'},
51-
#{'#{$penumbra-z-value} #{$color}'},
52-
#{$ambient-z-value} $color
52+
#{'#{$umbra-z-value} #{$shadow-color}'},
53+
#{'#{$penumbra-z-value} #{$shadow-color}'},
54+
#{$ambient-z-value} $shadow-color
5355
);
5456
@include mdc-elevation.shadow($box-shadow);
5557
}

0 commit comments

Comments
 (0)