Skip to content

Commit a8c92e6

Browse files
committed
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 angular#2901
1 parent 28f1ec3 commit a8c92e6

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/lib/button/_button-theme.scss

Lines changed: 12 additions & 4 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: default) {
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, 0.26);
3333
}
3434

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

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

@@ -97,11 +97,19 @@
9797

9898
@include _mat-button-theme-color($theme, 'color', default-contrast);
9999
@include _mat-button-theme-color($theme, 'background-color');
100+
@include _mat-button-ripple-color($theme, default-contrast);
100101
}
101102

103+
// TODO(devversion): The color class accent should be just set from TS code. No need for this.
102104
.mat-fab, .mat-mini-fab {
103105
background-color: mat-color($accent);
104106
color: mat-color($accent, default-contrast);
107+
108+
// Button fab elements are using the accent palette by default. The color classes won't
109+
// be set on the element. To have a proper ripple color for those, we set the ripple color.
110+
.mat-ripple-element {
111+
background-color: mat-color($accent, default-contrast, 0.26);
112+
}
105113
}
106114
}
107115

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)