Skip to content

Commit 4bdec36

Browse files
authored
Merge pull request #12522 from Arash1381-y/switch/add-keyboard-focus-behaviour
feat: add focus behavior to switch
2 parents 130e7f7 + 0d90520 commit 4bdec36

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

scss/components/_switch.scss

+23
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,18 @@
1010
/// @type Color
1111
$switch-background: $medium-gray !default;
1212

13+
/// Background color of a switch on focus.
14+
/// @type Color
15+
$switch-background-focus: scale-color($switch-background, $lightness: -10%) !default;
16+
1317
/// Background active color of a switch.
1418
/// @type Color
1519
$switch-background-active: $primary-color !default;
1620

21+
/// Background active color of a switch on focus.
22+
/// @type Color
23+
$switch-background-active-focus: scale-color($switch-background-active, $lightness: -15%) !default;
24+
1725
/// Height of a switch, with no class applied.
1826
/// @type Number
1927
$switch-height: 2rem !default;
@@ -140,6 +148,21 @@ $switch-cursor-disabled: not-allowed !default;
140148
}
141149
}
142150

151+
152+
// Change the visual style when the switch is focused
153+
input:focus-visible ~ & {
154+
background: $switch-background-focus;
155+
156+
&::after {
157+
background: $switch-paddle-background;
158+
}
159+
}
160+
161+
input:checked:focus-visible ~ & {
162+
background: $switch-background-active-focus;
163+
}
164+
165+
143166
// indicate a disabled switch
144167
input:disabled ~ & {
145168
cursor: $switch-cursor-disabled;

0 commit comments

Comments
 (0)