gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Post Settings toggle controls not keyboard focusable or triggerable

Open abrightclearweb opened this issue 9 years ago • 13 comments

Tested on: Gutenberg 0.3, 0.4.

Setup: Mac OS X Sierra, MAMP, Safari 10.1.1. Gutenberg is the only plugin active.

When tabbing through the Post Settings the Tab key can be used to open the panels and go through the controls one by one.

However, tabbing through does not focus on toggle controls such as the Pending review or Stick to front page toggles within the Status and Visibility section.

gutenberg post settings

Therefore these controls can't be activated by keyboard alone.

abrightclearweb avatar Jul 09 '17 16:07 abrightclearweb

It seems to me they're focusable and can be activated with a keyboard, but they miss a focus style. See #1562

afercia avatar Jul 09 '17 16:07 afercia

Got you. Activated with space bar. Agree re: focus style.

abrightclearweb avatar Jul 09 '17 16:07 abrightclearweb

Hm now that you made me think better at this, I see the potential issue. I knew these toggles are implemented with styled checkboxes so it was natural to me to use the spacebar. However, there's no reason why keyboard users should have a clue they're checkboxes. Only screen reader users will get them right because their screen reader will announce "checkbox". However, these toggles don't look like checkboxes, so sighted keyboard users will probably try to activate them pressing Enter. This is potentially confusing. Should the toggle work also when pressing Enter? /cc @jasmussen

afercia avatar Jul 09 '17 21:07 afercia

@afercia Any thoughts around implementing the toggles as <button>s with role="switch" and aria-checked attributes? Reading over this Toggle Buttons article; it might be doable, though slightly inconsistent support.

svinkle avatar Jul 10 '17 00:07 svinkle

@svinkle interesting. Yep, role="switch" is part of ARIA 1.1, still a Candidate Recommendation, and even Heydon warns about inconsistent support. So, as first thing we should have some data about support across the main assistive technologies. Also, I'm not sure I agree 100% on the proposed example on the article: <button role="switch" ... > because it goes against the second ARIA rule: don't change native semantics.

afercia avatar Jul 10 '17 07:07 afercia

@afercia @abrightclearweb It looks like the styles are based on the parent <span> vs. the <input> so :focus styles aren't going to go back upstream. The look and feel of that toggle would need to be coded from the <input> so when the element gained focus a visual indication of this focus would be visible.

A dirty temp hack would be to listen for focus w/JS and apply a class to the parent <span> to indicate focus... but who could sleep well after that?

joe-watkins avatar Jul 18 '17 21:07 joe-watkins

The purpose of introducing a "new" toggle element (as opposed to just using a checkbox), is to imply that once you toggle the switch, the action is already saved. A checkbox usually requires an explicit "Save" button later on in the page, or the check won't be saved.

I think the toggle is great for this. But we know we want it to be accessible. I would be reluctant to use JS hacks to make it accessible, especially if they aren't super simple. I'd rather look at alternate designs, including alternate markup. Remember, if we get the switch component right once, we get it right forever.

I know @afercia has mentioned that it's possible to make switch designs accessible, so I'm curious what we are doing wrong, CSS-wise, and how we might be able to do it differently.

jasmussen avatar Jul 21 '17 08:07 jasmussen

@jasmussen well it's not just an accessibility issue, it's also usability. A bit ironically, blind screen reader users are in the best position here: this control is reported as a checkbox (because it is a checkbox) and can be activated with the spacebar as native checkboxes do.

However, sighted keyboard users see something that doesn't look like a checkbox. Once the control is focused, they will likely try to activate it pressing Enter, and that won't do anything.

afercia avatar Jul 21 '17 09:07 afercia

P.S. as mentioned in other issues, to be fully accessible these switch toggles must always have a visible hint text on/off.

afercia avatar Jul 21 '17 09:07 afercia

I would be reluctant to use JS hacks to make it accessible, especially if they aren't super simple

I'd try this:

  • attach a ~click~ keydown event on the checkbox
  • when the checkbox is ~clicked~ activated with ENTER, trigger a click on its label
  • this is guaranteed to work if we keep the jsx-a11y label-has-for rule
  • of course, pending testing to check any potential negative impact

Will try a PR.

afercia avatar Jul 21 '17 09:07 afercia

P.S. as mentioned in other issues, to be fully accessible these switch toggles must always have a visible hint text on/off.

I have no problem making the visual label required instead of optional as it is now. Worst case we can switch the label place to be before or after the switch depending on the switch alignment (so the text length difference between on/off doesn't make it jump). And in cases of translations of on/off growing long, if testing suggests it necessary, perhaps we can make the font size smaller?

jasmussen avatar Jul 21 '17 09:07 jasmussen

OK I have a working solution but it uses DOM methods... 😬 The fact is, FormToggle is used in different ways: standalone or wrapped in a BaseControl component, so I couldn't think of a React-way to get its label. Any suggestions would be appreciated! /cc @aduth

afercia avatar Jul 21 '17 13:07 afercia

Screen options, for now, is punted, and the issue with the close button appears to be fixed:

screen shot 2017-12-05 at 12 02 10

For that reason, I'm closing this ticket as fixed. If this was in error, we can reopen.

jasmussen avatar Dec 05 '17 11:12 jasmussen