ARIA 1.1 Combobox with Listbox Popup Examples

The following three example comboboxes implement the ARIA 1.1 form of the combobox design pattern using a listbox popup. Each of the three comboboxes also demonstrates a different form of the autocomplete behaviors described in the design pattern.

In these examples, users can specify the name of a fruit or vegetable by either typing a value in the box or choosing from the list. The list becomes available after the textbox contains a character that matches the beginning of the name of one of the items in the list of suggested values. Users may type any value in the textbox; this implementation does not limit input to values that are in the list of suggested values.

Similar examples include:

Examples

Example 1: List Autocomplete with Manual Selection

Notes

List autocomplete with manual selection means that:

  1. When the listbox popup is displayed, it contains suggested values that complete or logically correspond to the characters typed in the textbox. In this implementation, the values in the listbox have names that start with the characters typed in the textbox.
  2. Users may set the value of the combobox by choosing a value from the list of suggested values.
  3. If the user does not choose a value from the listbox before moving focus outside the combobox, the value that the user typed, if any, becomes the value of the combobox.

Example 2: List Autocomplete with Automatic Selection

Notes

List autocomplete with automatic selection means that:

  1. When the listbox popup is displayed, it contains suggested values that complete or logically correspond to the characters typed in the textbox. In this implementation, the values in the listbox have names that start with the characters typed in the textbox.
  2. The first suggestion is automatically highlighted as selected.
  3. The automatically selected suggestion becomes the value of the textbox when the combobox loses focus unless the user chooses a different suggestion or changes the character string in the textbox.

Example 3: List with Inline Autocomplete

Notes

List with inline autocomplete means that:

  1. With the exception of one additional feature, this example has the same autocomplete behavior as the previous example that has list with automatic selection.
  2. The additional feature is that the portion of the selected suggestion that has not been typed by the user, a completion string, appears inline after the input cursor in the textbox.
  3. The inline completion string is visually highlighted and has a selected state.

Keyboard Support

The example comboboxes on this page implement the following keyboard interface. Other variations and options for the keyboard interface are described in the Keyboard Interaction section of the combobox design pattern.

Textbox

Key Function
Down Arrow
  • If the listbox is displayed:
    • Example 1: Moves focus to the first suggested value.
    • Examples 2 and 3: Moves focus to the second suggested value. Note that the first value is automatically selected.
  • If the listbox is not displayed, in example 3 only, opens the listbox and moves focus to the first value.
Up Arrow
  • If the listbox is displayed, moves focus to the last suggested value.
  • If the listbox is not displayed, in example 3 only, opens the listbox and moves focus to the last value.
Enter
  • Example 1: Does nothing.
  • Examples 2 and 3: If the listbox is displayed and the first option is automatically selected:
    • Sets the textbox value to the content of the selected option.
    • Closes the listbox.
Escape
  • Clears the textbox
  • If the listbox is displayed, closes it.
Standard single line text editing keys
  • Keys used for cursor movement and text manipulation, such as Delete and Shift + Right Arrow.
  • An HTML input with type=text is used for the textbox so the browser will provide platform-specific editing keys.

Listbox Popup

NOTE: When visual focus is in the listbox, DOM focus remains on the textbox and the value of aria-activedescendant on the textbox is set to a value that refers to the listbox option that is visually indicated as focused. Where the following descriptions of keyboard commands mention focus, they are referring to the visual focus indicator. For more information about this focus management technique, see Using aria-activedescendant to Manage Focus.

Key Function
Enter
  • Sets the textbox value to the content of the focused option in the listbox.
  • Closes the listbox.
  • Sets focus on the textbox.
Escape
  • Closes the listbox.
  • Sets focus on the textbox.
  • Clears the textbox.
Down Arrow
  • Moves focus to the next option.
  • If focus is on the last option, moves focus to the first option.
  • Note: This wrapping behavior is useful when Home and End move the editing cursor as described below.
Up Arrow
  • Moves focus to the previous option.
  • If focus is on the first option, moves focus to the last option.
  • Note: This wrapping behavior is useful when Home and End move the editing cursor as described below.
Right Arrow Moves focus to the textbox and moves the editing cursor one character to the right.
Left Arrow Moves focus to the textbox and moves the editing cursor one character to the left.
Home Moves focus to the textbox and places the editing cursor at the beginning of the field.
End Moves focus to the textbox and places the editing cursor at the end of the field.
Printable Characters
  • Moves focus to the textbox.
  • Types the character in the textbox.

Role, Property, State, and Tabindex Attributes

The example comboboxes on this page implement the following ARIA roles, states, and properties. Information about other ways of applying ARIA roles, states, and properties is available in the Roles, States, and Properties section of the combobox design pattern.

Combobox Container

Role Attribute Element Usage
combobox div
  • Identifies the element as a combobox.
  • Note:
    • Unlike this ARIA 1.1 combobox, an ARIA 1.0 pattern would have the combobox role on the textbox input instead of a parent container of the textbox.
    • The ARIA 1.1 pattern demonstrated on this page enables screen reader users to perceive both the input and the popup when using reading mode (see note below about aria-owns).
aria-haspopup=listbox div
  • Indicates that the combobox can popup a listbox to suggest values.
  • This is the default value for elements with the combobox role.
aria-owns=IDREF div
  • Refers to the element that serves as the listbox popup.
  • Tells browsers to arrange the screen reader reading order so the listbox, when it is visible, immediately follows the other elements inside the combobox, regardless of where the listbox element is in the DOM.
aria-expanded=false div Indicates that the popup element is not displayed.
aria-expanded=true div Indicates that the popup element is displayed.

Textbox

Role Attribute Element Usage
id="string" input[type="text"]
  • Referenced by for attribute of label element to provide an accessible label.
  • Recommended labeling method for HTML input elements so clicking label focuses input.
aria-autocomplete=list input[type="text"] Examples 1 and 2: Indicates that the autocomplete behavior of the text input is to suggest a list of possible values in a popup and that the suggestions are related to the string that is present in the textbox.
aria-autocomplete=both input[type="text"] Example 3: Indicates that the autocomplete behavior of the text input is to both show an inline completion string and suggest a list of possible values in a popup where the suggestions are related to the string that is present in the textbox.
aria-controls=IDREF input[type="text"]
  • Identifies the popup element that lists suggested values.
  • Note:
    • In the ARIA 1.0 combobox pattern, the textbox has aria-owns instead of aria-controls.
    • In this ARIA 1.1 pattern, aria-owns is instead on the parent container so the popup element is a sibling of the textbox instead of a child of the textbox, making it perceivable by screen reader users as an element adjacent to the textbox when using a reading cursor or touch interface.
aria-activedescendant=IDREF input[type="text"]
  • When an option in the listbox is visually indicated as having keyboard focus, refers to that option.
  • When navigation keys, such as Down Arrow, are pressed, the JavaScript changes the value.
  • Enables assistive technologies to know which element the application regards as focused while DOM focus remains on the input element.
  • For more information about this focus management technique, see Using aria-activedescendant to Manage Focus.

Listbox Popup

Role Attribute Element Usage
listbox ul Identifies the ul element as a listbox.
aria-labelledby=IDREF ul Provides a label for the listbox element of the combobox.
option li
  • Identifies the element as a listbox option.
  • The text content of the element provides the accessible name of the option.
aria-selected=true li
  • Specified on an option in the listbox when it is visually highlighted as selected.
  • In example 1, occurs only when an option in the list is referenced by aria-activedescendant.
  • In examples 2 and 3, also occurs when focus is in the textbox and the first option is automatically selected.

Javascript and CSS Source Code

HTML Source Code

Example 1

Example 2

Example 3