Skip to content

Commit b20aa28

Browse files
committed
fix(slide-toggle): respect primary palette of theme
* Instead of hard-coding the hue 500 for the checked color, the `default` hue for a palette should be used (falls back to 500 unless explicitly specified). This is similar to the MDC implementation and what the selection control specs show. * Fixes a missing thing for the 2018 spec alignment: The thumb bar should have a `0.54` opacity of the checked thumb color * Removes duplicate CSS for setting the unchecked ripple color. * Updates spec comments to refer to the reworked Material Design guidelines webpage. Fixes #11854
1 parent b2247f8 commit b20aa28

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

src/lib/slide-toggle/_slide-toggle-theme.scss

+22-25
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,16 @@
1111
}
1212

1313
.mat-slide-toggle-bar {
14-
background-color: mat-color($palette, $thumb-checked-hue, 0.5);
14+
// Opacity is determined from the specs for the selection controls.
15+
// See: https://material.io/design/components/selection-controls.html#specs
16+
background-color: mat-color($palette, $thumb-checked-hue, 0.54);
1517
}
16-
}
17-
}
1818

19-
// Applies the specified colors to the slide-toggle ripple elements.
20-
@mixin _mat-slide-toggle-ripple($palette, $ripple-unchecked-color, $ripple-checked-color) {
21-
&:not(.mat-checked) .mat-ripple-element {
22-
background-color: $ripple-unchecked-color;
23-
}
24-
.mat-ripple-element {
25-
background-color: $ripple-checked-color;
19+
.mat-ripple-element {
20+
// Set no opacity for the ripples because the ripple opacity will be adjusted dynamically
21+
// based on the type of interaction with the slide-toggle (e.g. for hover, focus)
22+
background-color: mat-color($palette, $thumb-checked-hue);
23+
}
2624
}
2725
}
2826

@@ -34,36 +32,35 @@
3432
$background: map-get($theme, background);
3533
$foreground: map-get($theme, foreground);
3634

37-
// Color hues based on the specs, which prescribe different hues for dark and light themes
38-
// https://material.google.com/components/selection-controls.html#selection-controls-switch
39-
$thumb-normal-hue: if($is-dark, 400, 50);
40-
$thumb-checked-hue: if($is-dark, 200, 500);
35+
// Color hues are based on the specs which briefly show the hues that are applied to a switch.
36+
// The 2018 specs no longer describe how dark switches should look like. Due to the lack of
37+
// information for dark themed switches, we keep the old behavior that is based on the previous
38+
// specifications. See: https://material.io/design/components/selection-controls.html#specs
39+
$thumb-unchecked-hue: if($is-dark, 400, 50);
40+
$thumb-checked-hue: if($is-dark, 200, default);
4141
$thumb-disabled-hue: if($is-dark, 800, 400);
4242

43-
$bar-normal-color: mat-color($foreground, disabled);
43+
$bar-unchecked-color: mat-color($foreground, disabled);
4444
$bar-disabled-color: if($is-dark, rgba(white, 0.12), rgba(black, 0.1));
4545

46-
// Ripple colors are based on the current palette and the state of the slide-toggle.
47-
// See https://material.google.com/components/selection-controls.html#selection-controls-switch
4846
$ripple-unchecked-color: mat-color($foreground, base);
49-
$ripple-primary-color: mat-color($primary, $thumb-checked-hue);
50-
$ripple-accent-color: mat-color($accent, $thumb-checked-hue);
51-
$ripple-warn-color: mat-color($warn, $thumb-checked-hue);
5247

5348
.mat-slide-toggle {
5449
@include _mat-slide-toggle-checked($accent, $thumb-checked-hue);
55-
@include _mat-slide-toggle-ripple($accent, $ripple-unchecked-color, $ripple-accent-color);
5650

5751
&.mat-primary {
5852
@include _mat-slide-toggle-checked($primary, $thumb-checked-hue);
59-
@include _mat-slide-toggle-ripple($accent, $ripple-unchecked-color, $ripple-primary-color);
6053
}
6154

6255
&.mat-warn {
6356
@include _mat-slide-toggle-checked($warn, $thumb-checked-hue);
64-
@include _mat-slide-toggle-ripple($accent, $ripple-unchecked-color, $ripple-warn-color);
6557
}
6658

59+
&:not(.mat-checked) .mat-ripple-element {
60+
// Set no opacity for the ripples because the ripple opacity will be adjusted dynamically
61+
// based on the type of interaction with the slide-toggle (e.g. for hover, focus)
62+
background-color: $ripple-unchecked-color;
63+
}
6764
}
6865

6966
.mat-disabled {
@@ -79,11 +76,11 @@
7976
}
8077

8178
.mat-slide-toggle-thumb {
82-
background-color: mat-color($mat-grey, $thumb-normal-hue);
79+
background-color: mat-color($mat-grey, $thumb-unchecked-hue);
8380
}
8481

8582
.mat-slide-toggle-bar {
86-
background-color: $bar-normal-color;
83+
background-color: $bar-unchecked-color;
8784
}
8885
}
8986

0 commit comments

Comments
 (0)