Editable Combobox with Grid Popup Example
The following example combobox implements the combobox design pattern using a grid for the suggested values popup.
In this example, users can specify the name of a fruit or vegetable by either typing a value in the box or choosing from the set of values presented in a grid popup. The popup becomes available after the textbox contains a character that matches the beginning of the name of one of the items in the set of value suggestions. Users may type any value in the textbox; this implementation does not limit input to values that are in the set of value suggestions.
The grid that presents suggested values has two columns. Each row of the grid represents one suggestion; column one contains the name of the fruit or vegetable and column two identifies whether it is a fruit or vegetable.
Similar examples include:
- Editable Combobox with Both List and Inline Autocomplete: An editable combobox that demonstrates the autocomplete behavior known as
list with inline autocomplete
. - Editable Combobox with List Autocomplete: An editable combobox that demonstrates the autocomplete behavior known as
list with manual selection
. - Editable Combobox Without Autocomplete: An editable combobox that demonstrates the behavior associated with
aria-autocomplete=none
.
Example
Keyboard Support
The example combobox on this page implements 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 grid is displayed, moves focus to the first suggested value. |
Up Arrow | If the grid is displayed, moves focus to the last suggested value. |
Escape |
|
Standard single line text editing keys |
|
Grid Popup
NOTE: When visual focus is in the grid, DOM focus remains on the textbox and the value of aria-activedescendant
on the textbox is set to a value that refers to an element in the grid 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 |
|
Left Arrow |
|
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.
Textbox
Role | Attribute | Element | Usage |
---|---|---|---|
combobox
|
input[type="text"] |
Identifies the element as a combobox. | |
aria-haspopup="grid"
|
input[type="text"] |
Indicates that the combobox can popup a grid to suggest values. |
|
aria-expanded="false"
|
input[type="text"] |
Indicates that the popup element is not displayed. | |
aria-expanded="true"
|
input[type="text"] |
Indicates that the popup element is displayed. | |
id="string"
|
input[type="text"] |
|
|
aria-autocomplete="list"
|
input[type="text"] |
Indicates that the autocomplete behavior of the input is to suggest a list of possible values in a popup. | |
aria-controls="IDREF"
|
input[type="text"] |
Identifies the popup element that lists suggested values. | |
aria-activedescendant="IDREF"
|
input[type="text"] |
|
Grid Popup
Role | Attribute | Element | Usage |
---|---|---|---|
grid
|
div
|
Identifies the element as a grid . |
|
aria-labelledby="IDREF"
|
div |
Provides a label for the grid element controlled by the combobox. |
|
row
|
div |
Identifies the element containing all the cells for a row. | |
aria-selected="true"
|
div |
|
|
gridcell |
div |
Identifies the element containing the content for a single cell. |
Javascript and CSS Source Code
- CSS: combobox.css
- Javascript: grid-combobox.js
- Javascript: grid-combo-example.js
HTML Source Code