Skip to content

Commit 7f65f31

Browse files
devversionjelbourn
authored andcommitted
fix(button): ripple color for raised buttons (#3829)
* fix(button): ripple color for raised buttons * Fixes the incorrect ripple color for raised buttons. Currently the ripple color is always based on black. This is incorrect on palettes like Indigo. Fixes #2901 * Address feedback * Distinguish between buttons with focus overlay * Fix comment
1 parent da33c03 commit 7f65f31

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

src/lib/button/_button-theme.scss

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@
2323
}
2424
}
2525

26-
@mixin _mat-button-ripple-color($theme) {
26+
@mixin _mat-button-ripple-color($theme, $hue, $opacity: 0.2) {
2727
$primary: map-get($theme, primary);
2828
$accent: map-get($theme, accent);
2929
$warn: map-get($theme, warn);
3030

3131
&.mat-primary .mat-ripple-element {
32-
background-color: mat-color($primary, 0.26);
32+
background-color: mat-color($primary, $hue, $opacity);
3333
}
3434

3535
&.mat-accent .mat-ripple-element {
36-
background-color: mat-color($accent, 0.26);
36+
background-color: mat-color($accent, $hue, $opacity);
3737
}
3838

3939
&.mat-warn .mat-ripple-element {
40-
background-color: mat-color($warn, 0.26);
40+
background-color: mat-color($warn, $hue, $opacity);
4141
}
4242
}
4343

@@ -75,19 +75,16 @@
7575
$foreground: map-get($theme, foreground);
7676

7777
.mat-button, .mat-icon-button, .mat-raised-button, .mat-fab, .mat-mini-fab {
78-
// Appy color to focus overlay.
78+
// Apply color to focus overlay.
7979
// The focus overlay will be visible when any button type is focused or when
8080
// flat buttons or icon buttons are hovered.
8181
@include _mat-button-focus-color($theme);
8282
}
8383

8484
.mat-button, .mat-icon-button {
85-
@include _mat-button-theme-color($theme, 'color');
8685
background: transparent;
87-
}
8886

89-
.mat-icon-button {
90-
@include _mat-button-ripple-color($theme);
87+
@include _mat-button-theme-color($theme, 'color');
9188
}
9289

9390
.mat-raised-button, .mat-fab, .mat-mini-fab {
@@ -97,11 +94,32 @@
9794

9895
@include _mat-button-theme-color($theme, 'color', default-contrast);
9996
@include _mat-button-theme-color($theme, 'background-color');
97+
98+
// Add ripple effect with contrast color to buttons that don't have a focus overlay.
99+
@include _mat-button-ripple-color($theme, default-contrast);
100+
}
101+
102+
// Add ripple effect with default color to flat buttons, which also have a focus overlay.
103+
.mat-button {
104+
@include _mat-button-ripple-color($theme, default, 0.1);
100105
}
101106

107+
// Add ripple effect with default color to the icon button. Ripple color needs to be stronger
108+
// since the icon button doesn't have a focus overlay.
109+
.mat-icon-button {
110+
@include _mat-button-ripple-color($theme, default);
111+
}
112+
113+
// TODO(devversion): The color class accent should be just set from TS code. No need for this.
102114
.mat-fab, .mat-mini-fab {
103115
background-color: mat-color($accent);
104116
color: mat-color($accent, default-contrast);
117+
118+
// Button fab elements are using the accent palette by default. The color classes won't
119+
// be set on the element. To have a proper ripple color for those, we set the ripple color.
120+
.mat-ripple-element {
121+
background-color: mat-color($accent, default-contrast, 0.2);
122+
}
105123
}
106124
}
107125

src/lib/core/theming/_theming.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@
4444
// @param $hue The hue from the palette to use. If this is a value between 0 and 1, it will
4545
// be treated as opacity.
4646
// @param $opacity The alpha channel value for the color.
47-
@function mat-color($palette, $hue: default, $opacity: 1) {
47+
@function mat-color($palette, $hue: default, $opacity: null) {
4848
// If hueKey is a number between zero and one, then it actually contains an
4949
// opacity value, so recall this function with the default hue and that given opacity.
5050
@if type-of($hue) == number and $hue >= 0 and $hue <= 1 {
5151
@return mat-color($palette, default, $hue);
5252
}
5353

5454
$color: map-get($palette, $hue);
55-
$opacity: if(opacity($color) < 1, opacity($color), $opacity);
55+
$opacity: if($opacity == null, opacity($color), $opacity);
5656

5757
@return rgba($color, $opacity);
5858
}

0 commit comments

Comments
 (0)