third_party/aria-practices/src/content/patterns/combobox/examples/combobox-autocomplete-none.html
The below combobox that enables users to choose a term from a hypothetical list of previously searched terms demonstrates the Combobox Pattern. The design pattern describes four types of autocomplete behavior. This example illustrates the autocomplete behavior known as no autocomplete. The terms that appear in the listbox popup are not related to the string that is present in the textbox. In this implementation, the listbox popup is not automatically triggered when the textbox receives focus; the list is opened when the user types a character into the textbox or through an explicit open command.
Similar examples include:
select element.Search
Browsers do not manage visibility of elements referenced by aria-activedescendant like they do for elements with focus. When a keyboard event changes the active option in the listbox, the JavaScript scrolls the option referenced by aria-activedescendant into view. Managing aria-activedescendant visibility is essential to accessibility for people who use a browser's zoom feature to increase the size of content.
To enhance perceivability when operating the combobox, visual keyboard focus and hover are styled using the CSS :hover pseudo-class, and focus and blur event handlers:
input and button elements with 2 pixels of space between the focus ring and the combobox.To ensure the inline SVG graphic used for the arrow in the open button has sufficient contrast with the background when high contrast settings change the color of text content, CSS forced-color-adjust is set to auto on the svg element and and the fill attribute of the polygon element is set to currentcolor. This causes the colors of the fill of the polygon elements to be overridden by the high contrast color setting. If forced-color-adjust were not used to override the colors specified for the fill property, the color would remain the same in high contrast mode, which could lead to insufficient contrast between the arrow and the background or even make it invisible if the color matched the high contrast mode background.
Note: The explicit setting of forced-color-adjust is necessary because some browsers do not use auto as the default value for SVG graphics.
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 Pattern.
| Key | Function |
|---|---|
| Down Arrow |
| | Alt + Down Arrow | Opens the listbox without moving focus or changing selection. | | Up Arrow |
| | Enter | Closes the listbox if it is displayed. | | Standard single line text editing keys |
input with type="text" is used for the textbox so the browser will provide platform-specific editing keys.|
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 Managing Focus in Composites Using aria-activedescendant.
| Key | Function |
|---|---|
| Enter |
| | Escape |
| | Down Arrow |
| | Up Arrow |
| | Right Arrow | Moves visual focus to the textbox and moves the editing cursor one character to the right. | | Left Arrow | Moves visual focus to the textbox and moves the editing cursor one character to the left. | | Home | Moves visual focus to the textbox and places the editing cursor at the beginning of the field. | | End | Moves visual focus to the textbox and places the editing cursor at the end of the field. | | Printable Characters |
|
The button has been removed from the tab sequence of the page, but is still important to assistive technologies for mobile devices that use touch events to open the list of options.
The example combobox on this page implements 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 Pattern.
| Role | Attribute | Element | Usage |
|---|---|---|---|
combobox | input[type="text"] | Identifies the input as a combobox. | |
aria-autocomplete="none" | input[type="text"] | Indicates that the suggestions in the combobox popup are not values that complete the current textbox input. | |
aria-controls="ID_REF" | input[type="text"] | Identifies the element that serves as the popup. | |
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"] |
for attribute of label element to provide an accessible name.|
| | aria-activedescendant="ID_REF" | input[type="text"] |
input element.|
| Role | Attribute | Element | Usage |
|---|---|---|---|
listbox | ul | Identifies the ul element as a listbox. | |
aria-label="Previous Searches" | ul | Provides a label for the listbox. | |
option | li |
listbox option.option.|
| | aria-selected="true" | li |
aria-activedescendant.|
| Role | Attribute | Element | Usage |
|---|---|---|---|
tabindex="-1" | button | Removes the button from the tab sequence of the page, since it's keyboard function is redundant with the keyboard operation of the textbox to open the listbox. | |
aria-label="Previous Searches" | button | Provides a label for the button. | |
aria-controls="ID_REF" | button | Identifies the element that serves as the popup. | |
aria-expanded="false" | button | Indicates that the popup element is not displayed. | |
aria-expanded="true" | button | Indicates that the popup element is displayed. |
To copy the following HTML code, please open it in CodePen.