WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.5k stars 4.2k forks source link

Switch toggles focus style #1562

Closed afercia closed 7 years ago

afercia commented 7 years ago

It would be great to have some design idea for the switch toggles focus style:

screen shot 2017-06-28 at 17 06 20

/cc @jasmussen @melchoyce 🙂

jasmussen commented 7 years ago

I actually tried adding a focus style to this a while back, and it seems like the way it's built it's hard to add such a thing :|

That doesn't mean it can't be done. It just means I couldn't get it done. But if we can't do it ever, we might want to look at an alternative.

The reason I like the switch as a form element is that it not only implies something is being toggled, but that the choice is also saved right then and there. Contrast to a checkbox, which is usually accompanied by a "Save Changes" button.

Given we can add a focus style to this switch, I like how Bear app does it:

bear

afercia commented 7 years ago

At Yoast, we use a similar UI control and we've implemented the focus style around the "knob" (built with two inner box-shadows). That's facilitated by the fact "our" toggle knob is a bit bigger, not sure a similar solution would fit the case of the Gutenberg switch toggle. Posting here for inspiration 🙂

switch toggle focus
jasmussen commented 7 years ago

I dig it. The visual style is less important, so long as we can add focus rectangles. Do you happen to have some markup we can look at? Thank you!

afercia commented 7 years ago

Markup no :) The CSS in our case is something like:

box-shadow:
    inset 0 0 0 1px #fff,
    0 0 0 1px #5b9dd9,
    0 0 2px 1px rgba(30, 140, 190, .8);

but this would beed to be adjusted, also because in the Gutenberg switch the background color becomes blue when active. The basic idea is:

dpersing commented 7 years ago

Hi all!

For focus states, I'd consider using a style other than box-shadow because it doesn't display correctly for low vision users relying on Windows High Contrast themes. High Contrast generally replaces default text and border colors and strips out background colors and shadows. Additionally, it displays background images in Edge only. Using a transparent border can make elements that rely on background color visible in High Contrast, but you'd still want an additional style, such as an upgraded outline, on focus, so that users can see the difference.

My coworker Joe made a Codepen demonstrating how box-shadow is removed in High Contrast. Here are a couple of screenshots showing the difference with and without the transparent border as well.

You can try out High Contrast by opening up the Windows display settings! 2017-07-06_11-08-31 2017-07-06_11-08-57

afercia commented 7 years ago

Hm, I'm afraid the High Contrast mode issue is something that hasn't been addressed in WordPress yet. Almost all focusable elements in the admin use box-shadow for the focus style. In Windows High Contrast mode there's basically no focus indication at all 😞 macOS instead seems to apply some outline. It is indeed something to address at a broader level and I'd propose to discuss it in the next a11y weekly meeting happening tomorrow (July 10) at 17:00 UTC on Slack #accessibility . @dpersing do feel free to join! Any feedback and help more than welcome.

dpersing commented 7 years ago

@afercia Sounds great! Looking forward to joining today.

afercia commented 7 years ago

Worth noting support for Windows High Contrast Mode is also mentioned in the initial accessibility recommendation issue, see point 5. in #297

afercia commented 7 years ago

I've played a bit with this. By changing the :after CSS generated pseudo element to a <span> we can easily target it when the input is focused using just CSS: input:focus + span. At this point we can apply any style, and we can also distinguish between the checked/not checked state. Just needs some design feedback. @jasmussen

Just as an example, not pretending these should be the final styles, I've tried to use some borders. Only the last style uses a border + box-shadow:

screen shot 2017-07-24 at 16 06 18

Maybe worth experimenting a bit inverting background/border colors.

afercia commented 7 years ago

Experimenting: normal, normal focused / checked, checked focused:

screen shot 2017-07-24 at 16 24 23