Using WAI-ARIA state and property attributes to expose the state of a user interface component
Status
- New technique.
- Surveyed by TF 6 Aug 2012
- Discussed in TF 6 Aug 2012
- 1 Nov 2012 Ready for review by WCAG WG pending LGR confirmation of tweaks
- Surveyed by WG 21 June 2013
- [Accepted by WG 22 July 2013]
- Added to XML by AWK Jan 2, 2014
Applicability
This technique applies to technologies that support WAI-ARIA, such as HTML.
WCAG references
- ensure-compat-rsv: Name, Role, Value (sufficient)
User Agent and Assistive Technology Support Notes [To be published separately]
Description
The objective of this technique is to use WAI-ARIA state and property attributes to expose the state, properties and values of a user interface component so that they can be read and set by assistive technology, and so that assistive technology is notified of changes to these values. The WAI-ARIA specification provides a normative description of each attribute, and the role of the user interface elements that they support. When rich internet applications define new user interface widgets, exposing the state and property attributes enables users to understand the widget and how to interact with it.
Examples
Example 1: A toggle button
A widget with role button
acts as a toggle button when it implements the attribute aria-pressed
. When aria-pressed
is true, the button is in a "pressed" state. When aria-pressed
is false, it is not pressed. If the attribute is not present, the button is a simple command button.
The following snippet from The Open Ajax Accessibility Examples, Example 38, shows WAI-ARIA mark-up for a toggle button that selects bold text:
<li id="bold1" class="toggleButton" role="button" tabindex="0" aria-pressed="false" aria-labelledby="bold_label" aria-controls="text1" ><img src="http://www.oaa-accessibility.org/media/examples/images/button-bold.png" alt="bold text" align="middle"></li>
The li
element has a role of "button" and an "aria-pressed" attribute. The following excerpt from the Javascript for this example updates the value of the "aria-pressed" attribute:
/** * togglePressed() toggles the aria-pressed atribute between true or false * * @param ( id object) button to be operated on * * @return N/A */ function togglePressed(id) { // reverse the aria-pressed state if ($(id).attr('aria-pressed') == 'true') { $(id).attr('aria-pressed', 'false'); } else { $(id).attr('aria-pressed', 'true'); } }
This button is available as part of the working example of Example 38 - Toolbar using inline images for visual state, on the OpenAjax Alliance site.
Example 2: A slider
A widget with role slider
lets a user select a value from within a given range. The slider represents the current value and the range of possible values via the size of the slider and the position of the handle. These properties of the slider are represented by the attributes aria-valuemin
, aria-valuemax
, and aria-valuenow
.
The following snippet from The Open Ajax Accessibility Examples, Example 32, shows WAI-ARIA mark-up for a slider created in Javascript. Note that the javascript sets the attributes aria-valuemin
, aria-valuemax
, and aria-valuenow
:
var handle = '<img id="' + id + '" class="' + (this.vert == true ? 'v':'h') +'sliderHandle" ' + 'src="http://www.oaa-accessibility.org/media/examples/images/slider_' + (this.vert == true ? 'v':'h') + '.png" ' + 'role="slider" ' + 'aria-valuemin="' + this.min + '" aria-valuemax="' + this.max + '" aria-valuenow="' + (val == undefined ? this.min : val) + '" aria-labelledby="' + label + '" aria-controls="' + controls + '" tabindex="0"></img>';
The following excerpt from the Javascript for this example updates the value of the "aria-valuenow" attribute when the value of the slider handle is changed:
slider.prototype.positionHandle = function($handle, val) { ... // Set the aria-valuenow position of the handle $handle.attr('aria-valuenow', val); ... }
This slider is available as part of the working example of Example 32 - Slider, on the OpenAjax Alliance site.
Resources
- Accessible Rich Internet Applications (WAI-ARIA) 1.0
- Accessible Rich Internet Applications (WAI-ARIA) 1.0, The Roles Model
- Accessible Rich Internet Applications (WAI-ARIA) 1.0, Supported States and Properties
- HTML to Platform Accessibility APIs Implementation Guide: HTML Attribute to Accessibility API State and Property Mapping Matrix
- WAI-ARIA 1.0 Primer
- WAI-ARIA 1.0 Authoring Practices
- Using ARIA in HTML
Related Techniques
- Using the role attribute to expose the role of a user interface component
- H91: Using HTML form controls and links
Tests
Procedure
The WAI-ARIA specification, Section 5.3, Categorization of Roles defines the required and inherited states and properties for each role.
For a user interface component using the WAI-ARIA role attribute:
- Check that the required states and properties for the role are present.
- Check that no WAI-ARIA states or properties that are neither required, supported, nor inherited are present.
- Check that the state and property values are updated to reflect the current state when the user interface component changes state.
Expected Results
- #1, #2 and #3 are true