Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add focus behavior to switch #12522

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions scss/components/_switch.scss
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