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

Add focus style to the switch toggle controls #1988

Merged
merged 2 commits into from
Jul 25, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/form-toggle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function FormToggle( { className, checked, id, onChange = noop, showHint = true
{ checked ? __( 'On' ) : __( 'Off' ) }
</span>
}
<span className="components-form-toggle__thumb"></span>
</span>
);
}
Expand Down
19 changes: 14 additions & 5 deletions components/form-toggle/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,34 @@ $toggle-border-width: 2px;
}
}

&:after {
content: '';
&__thumb {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a little bit obtuse, coding style wise. I admit to not being 100% sure about exactly what the coding guidelines would say, but I have a feeling it would be better to replace &__thumb with just plainly .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 + &__thumb {
background: $dark-gray-500;
}

&.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 ) ) );
}

.components-form-toggle__input:focus + .components-form-toggle__thumb {
background-color: $white;
}

&:before {
background-color: $blue-medium-500;
border: $toggle-border-width solid $blue-medium-500;
Expand Down