Skip to content

Commit c62330b

Browse files
zhaosiyangandrewseguin
authored andcommitted
fix(button): fix opacity is not added to ripple when using CSS variables to define custom theme
(cherry picked from commit 9ca0f0c)
1 parent e1760b6 commit c62330b

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/material/button/_button-theme.scss

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,32 @@ $_mat-button-ripple-opacity: 0.1;
2727
}
2828
}
2929

30+
// Applies the background color for a ripple. If the value provided is not a Sass color,
31+
// we assume that we've been given a CSS variable. Since we can't perform alpha-blending
32+
// on a CSS variable, we instead add the opacity directly to the ripple element.
33+
@mixin _mat-button-ripple-background($palette, $hue, $opacity) {
34+
$background-color: mat-color($palette, $hue, $opacity);
35+
background-color: $background-color;
36+
@if (type-of($background-color) != color) {
37+
opacity: $opacity;
38+
}
39+
}
40+
3041
@mixin _mat-button-ripple-color($theme, $hue, $opacity: $_mat-button-ripple-opacity) {
3142
$primary: map-get($theme, primary);
3243
$accent: map-get($theme, accent);
3344
$warn: map-get($theme, warn);
3445

3546
&.mat-primary .mat-ripple-element {
36-
background-color: mat-color($primary, $hue, $opacity);
47+
@include _mat-button-ripple-background($primary, $hue, $opacity);
3748
}
3849

3950
&.mat-accent .mat-ripple-element {
40-
background-color: mat-color($accent, $hue, $opacity);
51+
@include _mat-button-ripple-background($accent, $hue, $opacity);
4152
}
4253

4354
&.mat-warn .mat-ripple-element {
44-
background-color: mat-color($warn, $hue, $opacity);
55+
@include _mat-button-ripple-background($warn, $hue, $opacity);
4556
}
4657
}
4758

0 commit comments

Comments
 (0)