Skip to content

Commit

Permalink
Merge pull request #1988 from WordPress/update/switch-toggle-focus-style
Browse files Browse the repository at this point in the history
Add focus style to the switch toggle controls
  • Loading branch information
afercia authored Jul 25, 2017
2 parents b935bbf + 289e068 commit 1c7aaf8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
2 changes: 2 additions & 0 deletions components/form-toggle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ function FormToggle( { className, checked, id, onChange = noop, showHint = true
checked={ checked }
onChange={ onChange }
/>
<span className="components-form-toggle__track"></span>
<span className="components-form-toggle__thumb"></span>
{ showHint &&
<span className="components-form-toggle__hint" aria-hidden>
{ checked ? __( 'On' ) : __( 'Off' ) }
Expand Down
38 changes: 22 additions & 16 deletions components/form-toggle/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ $toggle-border-width: 2px;
.components-form-toggle {
position: relative;

&:before {
.components-form-toggle__track {
content: '';
display: inline-block;
vertical-align: top;
Expand All @@ -16,38 +16,44 @@ $toggle-border-width: 2px;
height: $toggle-height;
border-radius: $toggle-height / 2;
transition: 0.2s background ease;

.components-form-toggle.is-checked & {
background-color: $blue-medium-400;
border: $toggle-border-width solid $blue-medium-400;
}
}

&:hover:before {
&:hover .components-form-toggle__track {
background-color: $light-gray-500;
}

.components-form-toggle.is-checked & {
background-color: $blue-medium-500;
border: $toggle-border-width solid $blue-medium-500;
}
&.is-checked .components-form-toggle__track {
background-color: $blue-medium-400;
border: $toggle-border-width solid $blue-medium-400;
}

&:after {
content: '';
.components-form-toggle__thumb {
display: block;
position: absolute;
top: $toggle-border-width * 2;
left: $toggle-border-width * 2;
width: $toggle-height - ( $toggle-border-width * 4 );
height: $toggle-height - ( $toggle-border-width * 4 );
border-radius: 50%;
background: $dark-gray-500;
border: 2px solid $dark-gray-500;
background: $white;
transition: 0.1s transform ease;
}

&__input:focus {
& + .components-form-toggle__track {
box-shadow: 0 0 0 1px $white, 0 0 0 2px $blue-medium-400, 0 0 2px 2px $blue-medium-400;

& + .components-form-toggle__thumb {
border-width: 5px;
}
}
}

&.is-checked {
&:after {
background-color: $white;
.components-form-toggle__thumb {
border: 2px solid $white;
background-color: $blue-medium-500;
transform: translateX( $toggle-width - ( $toggle-border-width * 4 ) - ( $toggle-height - ( $toggle-border-width * 4 ) ) );
}

Expand Down

0 comments on commit 1c7aaf8

Please sign in to comment.