Skip to content

Commit 584ad3f

Browse files
crisbetommalerba
authored andcommitted
fix(slider): some potentially broken styles when using css var… (#17580)
Fixes a few places in the slider theme which can break if the consumer is using CSS variables for their theme.
1 parent 969d5c2 commit 584ad3f

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

src/material/slider/_slider-theme.scss

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626
$mat-slider-disabled-color: mat-color($foreground, slider-off);
2727
$mat-slider-labeled-min-value-thumb-color: mat-color($foreground, slider-min);
2828
$mat-slider-labeled-min-value-thumb-label-color: mat-color($foreground, slider-off);
29-
$mat-slider-focus-ring-color: mat-color($accent, default, 0.2);
30-
$mat-slider-focus-ring-min-value-color: mat-color($foreground, base, 0.12);
31-
$mat-slider-tick-color: mat-color($foreground, base, 0.7);
29+
$mat-slider-tick-opacity: 0.7;
30+
$mat-slider-tick-color: mat-color($foreground, base, $mat-slider-tick-opacity);
3231
$mat-slider-tick-size: 2px;
3332

3433
.mat-slider-track-background {
@@ -48,7 +47,15 @@
4847
}
4948

5049
.mat-slider-focus-ring {
51-
background-color: $mat-slider-focus-ring-color;
50+
$opacity: 0.2;
51+
$color: mat-color($accent, default, $opacity);
52+
background-color: $color;
53+
54+
// `mat-color` uses `rgba` for the opacity which won't work with
55+
// CSS variables so we need to use `opacity` as a fallback.
56+
@if (type-of($color) != color) {
57+
opacity: $opacity;
58+
}
5259
}
5360

5461
.mat-slider:hover,
@@ -74,7 +81,15 @@
7481

7582
.mat-slider-min-value {
7683
.mat-slider-focus-ring {
77-
background-color: $mat-slider-focus-ring-min-value-color;
84+
$opacity: 0.12;
85+
$color: mat-color($foreground, base, $opacity);
86+
background-color: $color;
87+
88+
// `mat-color` uses `rgba` for the opacity which won't work with
89+
// CSS variables so we need to use `opacity` as a fallback.
90+
@if (type-of($color) != color) {
91+
opacity: $opacity;
92+
}
7893
}
7994

8095
&.mat-slider-thumb-label-showing {
@@ -112,6 +127,12 @@
112127

113128
.mat-slider-has-ticks .mat-slider-wrapper::after {
114129
border-color: $mat-slider-tick-color;
130+
131+
// `mat-color` uses `rgba` for the opacity which won't work with
132+
// CSS variables so we need to use `opacity` as a fallback.
133+
@if (type-of($mat-slider-tick-color) != color) {
134+
opacity: $mat-slider-tick-opacity;
135+
}
115136
}
116137

117138
.mat-slider-horizontal .mat-slider-ticks {
@@ -121,11 +142,23 @@
121142
// (see https://bugzilla.mozilla.org/show_bug.cgi?id=1314319).
122143
background-image: -moz-repeating-linear-gradient(0.0001deg, $mat-slider-tick-color,
123144
$mat-slider-tick-color $mat-slider-tick-size, transparent 0, transparent);
145+
146+
// `mat-color` uses `rgba` for the opacity which won't work with
147+
// CSS variables so we need to use `opacity` as a fallback.
148+
@if (type-of($mat-slider-tick-color) != color) {
149+
opacity: $mat-slider-tick-opacity;
150+
}
124151
}
125152

126153
.mat-slider-vertical .mat-slider-ticks {
127154
background-image: repeating-linear-gradient(to bottom, $mat-slider-tick-color,
128155
$mat-slider-tick-color $mat-slider-tick-size, transparent 0, transparent);
156+
157+
// `mat-color` uses `rgba` for the opacity which won't work with
158+
// CSS variables so we need to use `opacity` as a fallback.
159+
@if (type-of($mat-slider-tick-color) != color) {
160+
opacity: $mat-slider-tick-opacity;
161+
}
129162
}
130163
}
131164

0 commit comments

Comments
 (0)