Skip to content

Commit 0153667

Browse files
authored
fix(material/slide-toggle): m3 track outline and handle opacity (#28565)
* fix(material/slide-toggle): m3 track outline * fix(material/slide-toggle): m3 disabled handle color and opacity * fix(material/slide-toggle): wrap hardcoded custom tokens * fixup! fix(material/slide-toggle): m3 track outline
1 parent 83b6ebc commit 0153667

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

src/material-experimental/theming/_custom-tokens.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,8 @@
11741174
/// @return {Map} A set of custom tokens for the mat-slide-toggle
11751175
@function switch($systems, $exclude-hardcoded) {
11761176
@return (
1177+
disabled-selected-handle-opacity: _hardcode(1, $exclude-hardcoded),
1178+
disabled-unselected-handle-opacity: _hardcode(0.38, $exclude-hardcoded),
11771179
unselected-handle-size: _hardcode(16px, $exclude-hardcoded),
11781180
selected-handle-size: _hardcode(24px, $exclude-hardcoded),
11791181
with-icon-handle-size: _hardcode(24px, $exclude-hardcoded),
@@ -1194,7 +1196,11 @@
11941196
hidden-track-opacity: _hardcode(0, $exclude-hardcoded),
11951197
visible-track-transition: _hardcode(opacity 75ms, $exclude-hardcoded),
11961198
hidden-track-transition: _hardcode(opacity 75ms, $exclude-hardcoded),
1197-
);
1199+
track-outline-width: _hardcode(2px, $exclude-hardcoded),
1200+
track-outline-color: map.get($systems, md-sys-color, outline),
1201+
disabled-unselected-track-outline-width: _hardcode(2px, $exclude-hardcoded),
1202+
disabled-unselected-track-outline-color: map.get($systems, md-sys-color, on-surface),
1203+
), ();
11981204
}
11991205

12001206
/// Generates custom tokens for the mat-snack-bar.

src/material/core/tokens/m2/mat/_switch.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ $prefix: (mat, switch);
88
// but may be in a future version of the theming API.
99
@function get-unthemable-tokens() {
1010
@return (
11+
disabled-selected-handle-opacity: 0.38,
12+
disabled-unselected-handle-opacity: 0.38,
13+
1114
unselected-handle-size: 20px,
1215
selected-handle-size: 20px,
1316
pressed-handle-size: 20px,
@@ -31,6 +34,11 @@ $prefix: (mat, switch);
3134
hidden-track-opacity: 1,
3235
visible-track-transition: transform 75ms 0ms cubic-bezier(0, 0, 0.2, 1),
3336
hidden-track-transition: transform 75ms 0ms cubic-bezier(0.4, 0, 0.6, 1),
37+
38+
track-outline-width: 1px,
39+
track-outline-color: transparent,
40+
disabled-unselected-track-outline-width: 1px,
41+
disabled-unselected-track-outline-color: transparent,
3442
);
3543
}
3644

src/material/core/tokens/m2/mdc/_switch.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $prefix: (mdc, switch);
1818
@function get-unthemable-tokens() {
1919
@return (
2020
// Opacity of handle when disabled.
21-
disabled-handle-opacity: 0.38,
21+
disabled-handle-opacity: null,
2222
// Opacity of icon when disabled and selected.
2323
disabled-selected-icon-opacity: 0.38,
2424
// Opacity of track when disabled.

src/material/slide-toggle/slide-toggle.scss

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,27 @@
212212
}
213213
}
214214
}
215+
216+
@include token-utils.use-tokens(m2-mat-switch.$prefix, m2-mat-switch.get-token-slots()) {
217+
.mdc-switch__track::after,
218+
.mdc-switch__track::before {
219+
@include token-utils.create-token-slot(border-width, track-outline-width);
220+
@include token-utils.create-token-slot(border-color, track-outline-color);
221+
}
222+
223+
.mdc-switch--disabled .mdc-switch__track::after,
224+
.mdc-switch--disabled .mdc-switch__track::before {
225+
@include token-utils.create-token-slot(border-width, disabled-unselected-track-outline-width);
226+
@include token-utils.create-token-slot(border-color, disabled-unselected-track-outline-color);
227+
}
228+
}
229+
230+
@include token-utils.use-tokens(m2-mat-switch.$prefix, m2-mat-switch.get-token-slots()) {
231+
.mdc-switch--disabled.mdc-switch--selected .mdc-switch__handle::after {
232+
@include token-utils.create-token-slot(opacity, disabled-selected-handle-opacity);
233+
}
234+
235+
.mdc-switch--disabled.mdc-switch--unselected .mdc-switch__handle::after {
236+
@include token-utils.create-token-slot(opacity, disabled-unselected-handle-opacity);
237+
}
238+
}

0 commit comments

Comments
 (0)