Problem/Motivation

The Radix theme markup for dismissible Drupal messages (errors, alerts, etc) generates inaccessible code. The Close button is natively focusable, but it is marked as aria-hidden="true". This will make it unusable for users of assistive technology such as screenreaders.

The Bootstrap accessibility JS includes a function to clean this up, but not all sites will be using that plugin.

Steps to reproduce

  1. Install a Drupal 7 site with a Radix-based theme that doesn't use the Bootstrap accessibility JS.
  2. Take an action that results in a Drupal status message being output to the browser - for example, create and save a node.
  3. View the source code of the resulting page.
  4. Note the markup of the status message:
<div id="messages">
  <div class="alert alert-success alert-dismissable">
    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
    Page <em class="placeholder">Test content page</em> has been created.
  </div>
</div>

Proposed resolution

There are several possible ways to mark this up:
Use an aria-label on the button and remove the aria-hidden attribute:

<div id="messages">
  <div class="alert alert-success alert-dismissable">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">&times;</button>
    Page <em class="placeholder">Test content page</em> has been created.
  </div>
</div>

Do the same thing that the Bootstrap JS does, and add screenreader-only text:

<div id="messages">
  <div class="alert alert-success alert-dismissable">
    <button type="button" class="close" data-dismiss="alert">
      <span aria-hidden="true">&times;</span>
      <span class="sr-only">Close</span>
    </button>
    Page <em class="placeholder">Test content page</em> has been created.
  </div>
</div>

The aria-label approach has one possible drawback, which is that element attributes are not usually translated by things like Google Translate.

Remaining tasks

  • Decide on best approach.
  • Patch and test.

User interface changes

None.

API changes

None.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cboyden created an issue. See original summary.

dsnopek’s picture

I think from the perspective of Radix, either approach is fine.

Looking at other Radix code (for precedents) it appears we're doing both approaches for the CTools modal:

<button type="button" class="close ctools-close-modal" aria-label="Close Window">&times; <span class="element-invisible">Close Window</span></button>

In any case, I trust your judgement on which you think is best from an accessibility perspective.

cboyden’s picture

Status: Active » Needs review
FileSize
1.03 KB

Here's a patch that adds (translatable) hidden text, and hides the × HTML entity.

@dsnopek the CTools modal is doing a bit of belt-and-suspenders. The aria-label will override all of the text in the button, so it's not necessary to do both that and the hidden text. For consistency's sake, it would be best to use the same method in both places.

There is some debate over which method is best overall. Some recent commentary supports using hidden text instead of aria-label - see aria-label Does Not Translate.

If that sounds reasonable, I can update the patch to do the same thing in the CTools modal.

  • doxigo committed f3fe3d06 on 7.x-3.x authored by cboyden
    Issue #3332429 by cboyden, dsnopek: Incorrect ARIA markup for...
doxigo’s picture

Status: Needs review » Fixed

Thank you both, applied to the latest 7.3.x dev

Status: Fixed » Closed (fixed)

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

cboyden’s picture

There was a typo in the committed patch - see updated patch and interdiff attached.

dsnopek’s picture

Status: Closed (fixed) » Needs review
cboyden’s picture

FileSize
1.03 KB

Corrected patch attached.