Using the listbox role

  • Revision slug: Accessibility/ARIA/ARIA_Techniques/Using_the_listbox_role
  • Revision title: Using the listbox role
  • Revision id: 50541
  • Created:
  • Creator: hhillen
  • Is current revision? No
  • Comment page created, 760 words added

Revision Content

Description

This technique demonstrates how to use the listbox role and describes the effect it has on browsers and assistive technology.

The listbox role is used to identify an element that creates a list from which a user may select one or more items which are static and, unlike HTML <select> elements, may contain images. When the role is added to an element, the browser will send out an accessible log event to assistive technology products which can then notify the user about it.

Each entry in the listbox should have a role of option and should be DOM children of listbox. If one or more entries are not DOM children of listbox, please see the ARIA best practices for details of additional properties that may need to be set.

When a list is tabbed to, the first item in the list will be selected if nothing else already is. Up/down arrows navigate the list, and pressing Shift + Up/Down arrows will move and extend the selection. Typing one or more letters will navigate the list items (same letter goes to each item starting with that, different letters go to the first item starting with that entire string). If the current item has an associated context menu, Shift+F10 will launch that menu. If list items are checkable, Space can be used to toggle checkboxes. For selectable list items, Space toggles their selection, Shift+Space can be used to select contiguous items, Ctrl+Arrow moves without selecting, and Ctrl+Space can be used to select non-contiguous items. It is recommended that a checkbox, link or other method be used to select all items, and Ctrl+A could be used as a shortcut key for this.

Possible effects on user agents and assistive technology 

When the listbox role is added to an element, or such an element becomes visible, the user agent should do the following:

  • Expose the element as having a listbox role in the operating system's accessibility API. Alternatively, if it is the child of or owned by a combobox, expose the element as a menu.
  • Fire an accessible listbox (or in special cases, menu) event using the operating system's accessibility API if it supports it.

Assistive technology products should listen for such an event and notify the user accordingly:

  • Screen readers should announce the label and role of the listbox when it gains focus. If an item is focused within the list, this should be announced next, followed by an indication of the item's position with the list if the screen reader supports this. As focus moves within the list, the screen reader should announce the relevant list items.
  • Screen magnifiers may enlarge the listbox.
Note: Opinons may differ on how assistive technology should handle this technique. The information provided above is one of those opinions and therefore not normative.

Examples

Example 1: A single select listbox that uses aria-activedescendant

The snippet below shows how the listbox role is added directly into the html source code. 

<div role="listbox" tabindex="0" id="listbox1" onclick="return listItemClick(event);" onkeydown="return listItemKeyEvent(event);" onkeypress="return listItemKeyEvent(event);" onfocus="this.className='focus';" onblur="this.className='blur';" aria-activedescendant="listbox1-1">
  <div role="option" id="listbox1-1" class="selected">Green</div>
  <div role="option" id="listbox1-2">Orange</div>
  <div role="option" id="listbox1-3">Red</div>
  <div role="option" id="listbox1-4">Blue</div>
  <div role="option" id="listbox1-5">Violet</div>
  <div role="option" id="listbox1-6">Periwinkle</div>
</div>

See the CodeTalks example for further details.

Working Examples:

Notes

  • To be keyboard accessible, authors should manage focus of all descendants of this role.
  • It is recommended that authors use different styling for the selection when the list is not focused, e.g. a non-active selection is often shown with a lighter background colour.
  • If the listbox is not part of another widget, it should have the aria-labelledby property set.
  • If one or more entries are not DOM children of listbox, additional aria-* properties will need to be set (see ARIA Best Practices).
  • If there is a valid reason to expand the listbox, the combobox role may be more appropriate.

ARIA attributes used

Related ARIA techniques 

Compatibility

TBD: Add support information for common UA and AT product combinations

Additional resources

Revision Source

<h3>Description</h3>
<p class="p1">This technique demonstrates how to use the <a class=" external" href="http://www.w3.org/TR/wai-aria/roles#listbox">listbox</a> role and describes the effect it has on browsers and assistive technology.</p>
<p class="p1">The listbox role is used to identify an element that creates a list from which a user may select one or more items which are static and, unlike HTML &lt;select&gt; elements, may contain images. When the role is added to an element, the browser will send out an accessible log event to assistive technology products which can then notify the user about it.</p>
<p class="p1">Each entry in the listbox should have a role of <a class=" external" href="http://www.w3.org/TR/2010/WD-wai-aria-20100916/roles#option">option</a> and should be DOM children of listbox. If one or more entries are not DOM children of listbox, please see the <a class=" external" href="http://www.w3.org/TR/wai-aria-practices/#listbox_div">ARIA best practices</a> for details of additional properties that may need to be set.</p>
<p class="p1">When a list is tabbed to, the first item in the list will be selected if nothing else already is. Up/down arrows navigate the list, and pressing Shift + Up/Down arrows will move and extend the selection. Typing one or more letters will navigate the list items (same letter goes to each item starting with that, different letters go to the first item starting with that entire string). If the current item has an associated context menu, Shift+F10 will launch that menu. If list items are checkable, Space can be used to toggle <a class=" external" href="http://www.w3.org/TR/wai-aria-practices/#checkbox">checkboxes</a>. For selectable list items, Space toggles their selection, Shift+Space can be used to select contiguous items, Ctrl+Arrow moves without selecting, and Ctrl+Space can be used to select non-contiguous items. It is recommended that a checkbox, link or other method be used to select all items, and Ctrl+A could be used as a shortcut key for this.</p>
<h3>Possible effects on user agents and assistive technology </h3>
<p class="p1">When the listbox role is added to an element, or such an element becomes visible, the user agent should do the following:</p>
<ul class="ul1"> <li class="li2">Expose the element as having a listbox role in the operating system's accessibility API. Alternatively, if it is the child of or owned by a <a class=" external" href="http://www.w3.org/TR/wai-aria/roles#combobox">combobox</a>, expose the element as a <a class=" external" href="http://www.w3.org/TR/wai-aria/roles#menu">menu</a>.</li> <li class="li2">Fire an accessible listbox (or in special cases, menu) event using the operating system's accessibility API if it supports it.</li>
</ul>
<p class="p1">Assistive technology products should listen for such an event and notify the user accordingly:</p>
<ul class="ul1"> <li class="li2">Screen readers should announce the label and role of the listbox when it gains focus. If an item is focused within the list, this should be announced next, followed by an indication of the item's position with the list if the screen reader supports this. As focus moves within the list, the screen reader should announce the relevant list items.</li> <li class="li2">Screen magnifiers may enlarge the listbox.</li>
</ul>
<div class="note"><strong>Note:</strong> Opinons may differ on how assistive technology should handle this technique. The information provided above is one of those opinions and therefore not normative.</div>
<h3>Examples</h3>
<h4 class="p1">Example 1: A single select listbox that uses aria-activedescendant</h4>
<p class="p2">The snippet below shows how the listbox role is added directly into the html source code. </p>
<pre class="brush: html">&lt;div role="listbox" tabindex="0" id="listbox1" onclick="return listItemClick(event);" onkeydown="return listItemKeyEvent(event);" onkeypress="return listItemKeyEvent(event);" onfocus="this.className='focus';" onblur="this.className='blur';" aria-activedescendant="listbox1-1"&gt;
  &lt;div role="option" id="listbox1-1" class="selected"&gt;Green&lt;/div&gt;
  &lt;div role="option" id="listbox1-2"&gt;Orange&lt;/div&gt;
  &lt;div role="option" id="listbox1-3"&gt;Red&lt;/div&gt;
  &lt;div role="option" id="listbox1-4"&gt;Blue&lt;/div&gt;
  &lt;div role="option" id="listbox1-5"&gt;Violet&lt;/div&gt;
  &lt;div role="option" id="listbox1-6"&gt;Periwinkle&lt;/div&gt;
&lt;/div&gt;
</pre>
<p class="p3">See the CodeTalks <a class=" external" href="http://codetalks.org/source/widgets/listbox/listbox.html">example</a> for further details.</p>
<h4 class="p1">Working Examples:</h4>
<ul class="ul1"> <li class="li3"><a class=" external" href="http://codetalks.org/source/widgets/listbox/listbox.html">http://codetalks.org/source/widgets/listbox/listbox.html</a></li> <li class="li3"><a class=" external" href="http://codetalks.org/source/widgets/listbox/listbox-owner.html">http://codetalks.org/source/widgets/listbox/listbox-owner.html</a></li> <li class="li3"><a class=" external" href="http://developer.yahoo.com/yui/examples/carousel/carousel-ariaplugin_source.html">http://developer.yahoo.com/yui/examples/carousel/carousel-ariaplugin_source.html</a></li>
</ul>
<h3 class="p5">Notes</h3>
<ul class="ul1"> <li class="li3">To be keyboard accessible, authors should <a class=" external" href="http://www.w3.org/TR/wai-aria/roles#option">manage focus</a> of all descendants of this role.</li> <li class="li3">It is recommended that authors use different styling for the selection when the list is not focused, e.g. a non-active selection is often shown with a lighter background colour.</li> <li class="li3">If the listbox is not part of another widget, it should have the <a class=" external" href="http://www.w3.org/TR/2010/WD-wai-aria-20100916/states_and_properties#aria-labelledby"><span class="s1">aria-labelledby</span></a> property set.</li> <li class="li3">If one or more entries are not DOM children of listbox, additional <span class="s1">aria-*</span> properties will need to be set (see <a class=" external" href="http://www.w3.org/TR/wai-aria-practices/#listbox_div">ARIA Best Practices</a>).</li> <li class="li3">If there is a valid reason to <a class=" external" href="http://www.w3.org/TR/wai-aria/states_and_properties#aria-expanded">expand</a> the listbox, the <a class=" external" href="http://www.w3.org/TR/wai-aria/roles#combobox">combobox</a> role may be more appropriate.</li>
</ul>
<h3 class="p5">ARIA attributes used</h3>
<ul class="ul1"> <li class="li2"><a class=" external" href="http://www.w3.org/TR/wai-aria/roles#listbox">listbox</a></li>
</ul>
<p class="p5"><strong>Related ARIA techniques </strong></p>
<ul class="ul1"> <li class="li2"><a class=" external" href="http://www.w3.org/TR/wai-aria/roles#combobox">combobox</a> role</li>
</ul>
<h3 class="p5">Compatibility</h3>
<p class="p2">TBD: Add support information for common UA and AT product combinations</p>
<p class="p5"><strong>Additional resources</strong></p>
<ul class="ul1"> <li class="li2">ARIA Best Practices – Listbox: <a class=" external" href="http://www.w3.org/TR/wai-aria-practices/#listbox_div">http://www.w3.org/TR/wai-aria-practices/#listbox_div</a></li>
</ul>
Revert to this revision