Skip to content

Commit

Permalink
Merge pull request #12522 from Arash1381-y/switch/add-keyboard-focus-…
Browse files Browse the repository at this point in the history
…behaviour

feat: add focus behavior to switch
  • Loading branch information
joeworkman authored Sep 27, 2024
2 parents 130e7f7 + 0d90520 commit 4bdec36
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions scss/components/_switch.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@
/// @type Color
$switch-background: $medium-gray !default;

/// Background color of a switch on focus.
/// @type Color
$switch-background-focus: scale-color($switch-background, $lightness: -10%) !default;

/// Background active color of a switch.
/// @type Color
$switch-background-active: $primary-color !default;

/// Background active color of a switch on focus.
/// @type Color
$switch-background-active-focus: scale-color($switch-background-active, $lightness: -15%) !default;

/// Height of a switch, with no class applied.
/// @type Number
$switch-height: 2rem !default;
Expand Down Expand Up @@ -140,6 +148,21 @@ $switch-cursor-disabled: not-allowed !default;
}
}


// Change the visual style when the switch is focused
input:focus-visible ~ & {
background: $switch-background-focus;

&::after {
background: $switch-paddle-background;
}
}

input:checked:focus-visible ~ & {
background: $switch-background-active-focus;
}


// indicate a disabled switch
input:disabled ~ & {
cursor: $switch-cursor-disabled;
Expand Down

0 comments on commit 4bdec36

Please sign in to comment.