Thanks to @merlinofchaos in #1963124-7: Resolve WCAG2 accessibility errors on main settings page I learned that the #states mechanism uses CSS display:none; to hide content.

Unfortunately, this means that for screen reader users, nothing gets presented to the user. For a keyboard only user this isn't a problem because when they select a checkbox new ones appear, but screen reader users need to either have access to all of the checkboxes or be alerted that there is a change to the page.

I think the best approach is to simply mimic what we did with element-hidden & element-invisible and make a:

.js .js-hide {
 display: none;
}
.js .js-invisible {
  position: absolute !important;
  clip: rect(1px, 1px, 1px, 1px);
  overflow: hidden;
  height: 1px;
  width: 1px;
  word-wrap: normal;
}

I think that would address the problem, but it ties into core/misc/states.js

Any thoughts on this would be appreciated.

Comments

larowlan’s picture

Ouch! This will be great if we can refactor that easily.

mgifford’s picture

I think this would involve adding a hidden state to states.js

/**
 * This list of aliases is used to normalize states and associates negated names
 * with their respective inverse state.
 */
states.State.aliases = {
  'enabled': '!disabled',
  'invisible': '!visible',
  'hidden': '!visible',
  'invalid': '!valid',
  'untouched': '!touched',
  'optional': '!required',
  'filled': '!empty',
  'unchecked': '!checked',
  'irrelevant': '!relevant',
  'expanded': '!collapsed',
  'open': '!collapsed',
  'closed': 'collapsed',
  'readwrite': '!readonly'
};

But I'm really not sure how the visible/invisible code works here:

$(document).bind('state:visible', function(e) {
  if (e.trigger) {
    $(e.target).closest('.form-item, .form-submit, .form-wrapper').toggle(e.value);
  }
});

Or how to add a 3rd state to this.

mgifford’s picture

Status: Active » Needs review

Getting an initial patch rolling for testing. Maybe it can all be just visually hidden rather than adding a new state.

mgifford’s picture

StatusFileSize
new493 bytes

Thought it was attached. Also, here's a related issue #1899836: Accessibility improvements for States API

mgifford’s picture

seutje’s picture

odd, I wanted to group the selectors with .element-hidden, but I couldn't find it anywhere in core CSS, even though it's still being used as a class o.O

I take it .visually-hidden wouldn't work for this use-case?

mgifford’s picture

This is the table between D7 & D8 with the hidden/invisible changes:

D7 D8 Effect
element-hidden hidden Hide for everybody
element-invisible visually-hidden Hide visually but make available for screen readers
element-focusable visually-hidden.focusable Allow the element to be focusable when navigated to via the keyboard
invisible Hide visually and from screen readers, but maintain layout

Hope this clarifies things.

mgifford’s picture

Issue tags: -JavaScript, -Accessibility
mgifford’s picture

jhedstrom’s picture

Issue summary: View changes
Issue tags: +Needs manual testing

Patch still applies--were folks agreed on this fix? The table in #7 is a great overview.

mgifford’s picture

Issue summary: View changes
StatusFileSize
new546 bytes

The base is here core/modules/system/css/system.module.css

.visually-hidden {
  position: absolute !important;
  clip: rect(1px, 1px, 1px, 1px);
  overflow: hidden;
  height: 1px;
  width: 1px;
  word-wrap: normal;
}

I'm not sure what is extended by /* @extend .visually-hidden */in core/themes/bartik/css/style.css

It is slightly different in core/modules/config_translation/css/config_translation.admin.css

It is missing the word-wrap: normal; in:

 .config-translation-form .translation-element-wrapper .translation label {
  position: absolute !important;
  clip: rect(1px, 1px, 1px, 1px);
  overflow: hidden;
  height: 1px;
  width: 1px;
}

I'll file an issue for config_translation.admin.css so that it keeps up.

The last submitted patch, 4: drupal_process_states-1966990-3.patch, failed testing.

damienmckenna’s picture

Is this something that could be backported to D7? There are some efforts to improve the CTools / Panels world, e.g. #1963124: Resolve WCAG2 accessibility errors on main settings page, #2280853: Keyboard trap when using ctools modal, but would core improvements be considered?

mgifford’s picture

In general I would think so, but .js-hide isn't used in D7. Right now ctools 7 is using display:none; in several places css/dropdown.css, css/collapsible-div.css, css/dropbutton.css, js/modal.js, page_manager/css/page-manager.css

It would be good for someone who knows ctools better to verify that it shouldn't be used in all of these cases. If it doesn't convey any semantic meaning, then display:none; is ok, but often there is meaning which is obscured.

damienmckenna’s picture

Issue tags: +Accessibility

Status: Needs review » Needs work

The last submitted patch, 12: drupal_process_states-1966990-12.patch, failed testing.

mgifford’s picture

Status: Needs work » Needs review
StatusFileSize
new524 bytes
larowlan’s picture

Correct me if I'm wrong, but this would mean that the screenreader reads the fields aloud.
I've commonly used states to build a form on the client-side without needing AJAX calls, to save on server load/round trips.
In these instances the hidden fields should not be read until such time as the particular selection has been made.
And in those instances I think we'd want to use Drupal.announce to announce their presence?
Thoughts?

mgifford’s picture

Hmm.. True.. It would be better to use Drupal.announce in those cases.

I don't know the process states well enough to know if we could build in a Drupal.announce call automatically when the selection is made.

Having it read outloud twice is better than not having it be visible at all. What are the best defaults here to see that we can make this accessible to the broadest base?

mgifford’s picture

Title: Forms API drupal_process_states() hides content using CSS display:none; » Forms API drupal_process_states() hidden content is not visible to screen readers

Changing title of this issue to allow for a better solution.

mgifford’s picture

Status: Needs review » Needs work

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +Bug Smash Initiative

doing Bug Smash triage,

There hasn't been any discussion here in 7 years, has this been fixed in the meantime?

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Since there hasn't been a follow up to #36 in a year going to close for now.

But please if still a bug reopen, updating issue summary where needed.

Thanks!