Problem/Motivation

The toggle element provided by webform is a custom UI element, and the current implementation is inaccessible.

  • Sighted keyboard users cannot focus the toggle switch to operate it (likewise screen readers).
  • Even if they were focusable, the semantics are wrong. The current implementation is combination of a hidden checkbox (not passed to OS accessibility API) and cosmetic DIVs with no machine readable semantics. Screenreader users may well be unaware that the toggle elements exist at all.

Proposed resolution

  • Devise a new markup/JS pattern, aim to follow practices in WAI-ARIA and ARIA Authoring Practices. Can we use a simple <button> with aria-pressed, instead of managing cosmetic DIVs and a hidden checkbox in parallel?
  • Rework Drupal.behaviors.webformToggle JS and WebformToggle::preRenderCheckbox() as appropriate.
  • Note 1: the webform element "title" setting should end up being the computed accessible name for the button.
  • Note 2: there are single and multiple versions of this element available. Using the "toggles" version already wraps them up together with fieldset/legend elements, and uses aria-describedby to associate the "description" setting with the fieldset. In other words, this already works like radios and checkboxes, so doesn't need fixing here. Confirm it still works though...
  • Note 3: The webform "description" should be associated with single-toggle elements using aria-describedby directly on the button element itself.
  • Note 4: the forthcoming ARIA 1.1 (candidate recommendation currently) introduces a new "switch" role, which aims to get around the semantic debate of whether to use a button or a checkbox role for these things. It looks ideal, however it's brand new and we should avoid using this until we know it has good support across many browser/AT combinations. For now, <button aria-pressed="true"> is a more reliable pattern.
  • Question 1: how do we convey the custom toggle-off and toggle-on text (which appear inside the switch background? These are not the same as the <label>. Do we assume they are cosmetic, or should we include a Drupal.announce(), or something else? Discuss :-)
  • Question 2: do we need to update the way WebformToggles render element PHP class works? It seems to work by changing the render type of it's children. Fingers crossed we might not need to touch this one.

Remaining tasks

  • Manual testing is essential! Keyboard-only, and a variety of screen readers.
  • Functional javascript tests are possible, triggering keyboard events on the toggle button. Assert (e.g.) that the toggle-off text has gone, and the toggle-on text has appeared, or just test for expected class attribute values.

User interface changes

No visual changes are needed. This is all about keyboard operation, and conveying dynamic state semantics to assistive technology.

API changes

None.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andrewmacpherson created an issue. See original summary.

andrewmacpherson’s picture

Issue tags: +sprint

This could be a good issue to look at during this weekend's accessibility sprint in Amsterdam, while we have many a11y heads in the same room.

andrewmacpherson’s picture

Issue summary: View changes
andrewmacpherson’s picture

Issue summary: View changes
jrockowitz’s picture

@andrewmacpherson A few thoughts...

  • Could the issue be fixed in the jQuery Toggles library?
  • Are there any external libraries that are more accessible?
  • We should first create a new webform element that could then replace the webform toggle element.
  • Maybe we should create a documentation page with a table that tracks the accessibility of all elements.
  • Or add accessibility notes to each WebformElement's annotation which could be displayed on /admin/structure/webform/settings/elements.
lomale@bluewin.ch’s picture

Category: Bug report » Support request

Screenreader users may well be unaware that the toggle elements exist at all.

This is exactly my problem. I have a lot of people that are not aware when submitting a registration that the should say YES to the first element

toggle_advanced:
'#type': toggle
'#title': 'I will participate at the next training with …..'
'#title_display': before
'#description_display': before
'#admin_title': registration
'#toggle_theme': iphone
'#toggle_size': large
'#on_text': 'YES'
'#off_text': 'NO'

because there is no required, they can let it filled with NO

could there be a way; when they accept the

termsofservice:
'#type': checkbox
'#title': 'I accept the terms of service'
'#title_display': before
'#field_suffix': 'JA / YES'
'#icheck': square-blue
'#required': true
'#required_error': 'please accept our terms of service'
'#admin_title': 'terms of service accepted‘

which is required that the
toggle_advanced:
'#type': toggle
would be set on YES

or would you suggest that I interchange the
'#on_text': 'YES'
'#off_text': 'NO'

because if i put a condition logic on the submit button
actions:
'#type': webform_actions
'#title': 'Submit button(s)'
'#submit__label': 'Submit'

lot of people claimed that the submit does not work.

Any suggestions to this problem.

Thanks

jrockowitz’s picture

I just happened upon this code snippet.

https://www.w3schools.com/howto/howto_css_switch.asp

Is this approach more accessible? I think the .switch input {display:none;} might be an issue.

It is definitely much much simpler.

Here is an example of CSS library on GitHub.

https://ghinda.net/css-toggle-switch/

jrockowitz’s picture

@andrewmacpherson Thank you for spending the time to review this element.

The accessibility and maintenance of element are not great.

I am leaning toward deprecating the Toggle element and removing it at some point in the future.

The depreciation would mean the library (https://github.com/simontabor/jquery-toggles/) is not installed by default which will disable the element. An update hook can disable the library for websites that are not using the toggle element.

I am not seeing any external libraries that implement a well-maintained and accessible switch.

jrockowitz’s picture

Title: Webform toggle element is not accessible » [accessibility] Webform toggle element is deprecated
Status: Active » Needs review
Related issues: +#2979628: [meta] Improve Webform Accessibility
FileSize
5.6 KB

Status: Needs review » Needs work

The last submitted patch, 9: 2890861-9.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jrockowitz’s picture

Status: Needs work » Needs review
FileSize
6.33 KB
jrockowitz’s picture

jrockowitz’s picture

Status: Needs review » Reviewed & tested by the community

  • jrockowitz committed 2bf9be4 on 8.x-5.x
    Issue #2890861 by jrockowitz: [accessibility] Webform toggle element is...
jrockowitz’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.