-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice work, thank you for doing this. This is a vast improvement.
I wish we could attach an outline or box shadow to the whole element, as opposed to just the thumb inside, but given we can't do that (because it's the input that gets focus and we can't attach a ::before
to that), this seems like a good compromise. Designwise, thumbs up!
components/form-toggle/style.scss
Outdated
@@ -32,25 +32,34 @@ $toggle-border-width: 2px; | |||
} | |||
} | |||
|
|||
&:after { | |||
content: ''; | |||
&__thumb { |
There was a problem hiding this comment.
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
.
Actually, I think it can be done 🙁 following the same approach and replacing |
Playing a bit: on the Bear app it's nicer because the box-shadow has a different color than the background. Instead, the WordPress box-shadow default color is blue so when is-checked and focused, it looks a bit too big: One option could be adding a first 1 pixel white box-shadow: or maybe use a different color? It's just a matter of a design choice, I think the approach works. One thing that needs to be changed for a11y is that the "thumb" shouldn't be filled with the background when focused, we should increase the border-width instead. Because:
|
I'm going with the white + blue box-shadow for now, can be changed of course. Should be tested on IE 11, not possible at the moment: see #1397 and #1863. I've tested it also with the "hint" visible (see screenshot below on the left) and in Windows High Contrast mode where the focus state works because the "thumb" is filled increasing the border width (screensnot on the right): |
Love this. Very impressive work. Ship ship ship. |
The builds fail because of... aliens! 👽 |
This PR is a first try to add a focus style to the switch toggle UI control (FormToggle component).
It changes the CSS generated element (:after) previously used to style the switch "thumb" to a span element. This way it's trivial to target it when the input has focus and it is possible to use any style. For a11y reasons, it's better to use a border for the focus style, see the discussion on the issue about Windows High Contrast mode.
Pending design and a11y feedback.
Fixes #1562