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:
- ARIA 1.1 Combobox with Grid Popup: A combobox that presents suggestions in a grid, enabling users to navigate descriptive information about each suggestion.
- ARIA 1.0 Combobox with Both List and Inline Autocomplete: A combobox that demonstrates the autocomplete behavior known as
list with inline autocomplete
and uses the ARIA 1.0 implementation pattern. - ARIA 1.0 Combobox with List Autocomplete: A combobox that demonstrates the autocomplete behavior known as
list with manual selection
and uses the ARIA 1.0 implementation pattern. - ARIA 1.0 Combobox Without Autocomplete: A combo box that demonstrates the behavior associated with
aria-autocomplete=none
and uses the ARIA 1.0 implementation pattern.
Examples
Example 1: List Autocomplete with Manual Selection
Notes
List autocomplete with manual selection means that:
- 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.
- Users may set the value of the combobox by choosing a value from the list of suggested values.
- 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:
- 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.
- The first suggestion is automatically highlighted as selected.
- 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:
- With the exception of one additional feature, this example has the same autocomplete behavior as the previous example that has list with automatic selection.
- 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.
- 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 |
|
Up Arrow |
|
Enter |
|
Escape |
|
Standard single line text 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 |
|
Escape |
|
Down Arrow |
|
Up Arrow |
|
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 |
|
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 |
|
|
aria-haspopup=
|
div |
|
|
aria-owns=
|
div |
|
|
aria-expanded=
|
div |
Indicates that the popup element is not displayed. | |
aria-expanded=
|
div |
Indicates that the popup element is displayed. |
Textbox
Role | Attribute | Element | Usage |
---|---|---|---|
id="string"
|
input[type="text"] |
|
|
aria-autocomplete=
|
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=
|
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=
|
input[type="text"] |
|
|
aria-activedescendant=
|
input[type="text"] |
|
Listbox Popup
Role | Attribute | Element | Usage |
---|---|---|---|
listbox
|
ul
|
Identifies the ul element as a listbox . |
|
aria-labelledby=
|
ul |
Provides a label for the listbox element of the combobox. |
|
option
|
li |
|
|
aria-selected=
|
li |
|
Javascript and CSS Source Code
- CSS: combobox-1.1.css
- Javascript: listbox-combobox.js
- Javascript: listbox-combo-example.js
HTML Source Code
Example 1
Example 2
Example 3