![](/style/images/good.png)
![](/style/images/bad.png)
ARIA 1.1 Combobox with Listbox Popup Examples
source link: https://www.w3.org/TR/wai-aria-practices/examples/combobox/aria1.1pattern/listbox-combo.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
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
![arrow_drop_down_grey_27x27.png](https://www.w3.org/TR/wai-aria-practices/examples/combobox/aria1.1pattern/imgs/arrow_drop_down_grey_27x27.png)
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- 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.
- 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.
- 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.
- Clears the textbox
- If the listbox is displayed, closes it.
- Keys used for cursor movement and text manipulation, such as Delete and Shift + Right Arrow.
- An HTML
input
withtype=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.
- Sets the textbox value to the content of the focused option in the listbox.
- Closes the listbox.
- Sets focus on the textbox.
- Closes the listbox.
- Sets focus on the textbox.
- Clears the textbox.
- 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.
- 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.
- 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 Usagecombobox
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).
- Unlike this ARIA 1.1 combobox, an ARIA 1.0 pattern would have the
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 Usageid="string"
input[type="text"]
- Referenced by
for
attribute oflabel
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 ofaria-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.
- In the ARIA 1.0 combobox pattern, the textbox has
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 Usagelistbox
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.
HTML Source Code
Example 1
<label for="ex1-input"
id="ex1-label"
class="combobox-label">
Choice 1 Fruit or Vegetable
</label>
<div class="combobox-wrapper">
<div role="combobox"
aria-expanded="false"
aria-owns="ex1-listbox"
aria-haspopup="listbox"
id="ex1-combobox">
<input type="text"
aria-autocomplete="list"
aria-controls="ex1-listbox"
id="ex1-input">
</div>
<ul aria-labelledby="ex1-label"
role="listbox"
id="ex1-listbox"
class="listbox hidden">
</ul>
</div>
Example 2
<label id="ex2-label" class="combobox-label">
Choice 2 Fruit or Vegetable
</label>
<div class="combobox-wrapper">
<div role="combobox"
aria-expanded="false"
aria-owns="ex2-listbox"
aria-haspopup="listbox"
id="ex2-combobox">
<input type="text"
aria-autocomplete="list"
aria-controls="ex2-listbox"
aria-labelledby="ex2-label"
id="ex2-input">
</div>
<ul aria-labelledby="ex2-label"
role="listbox"
id="ex2-listbox"
class="listbox hidden">
</ul>
</div>
Example 3
<label id="ex3-label" class="combobox-label">
Choice 3 Fruit or Vegetable
</label>
<div class="combobox-wrapper">
<div role="combobox"
aria-expanded="false"
aria-owns="ex3-listbox"
aria-haspopup="listbox"
id="ex3-combobox">
<input type="text"
aria-autocomplete="both"
aria-controls="ex3-listbox"
aria-labelledby="ex3-label"
id="ex3-input">
<div class="combobox-dropdown"
id="ex3-combobox-arrow"
tabindex="-1"
role="button"
aria-label="Show vegetable options">
<img src="imgs/arrow_drop_down_grey_27x27.png" alt="">
</div>
</div>
<ul aria-labelledby="ex3-label"
role="listbox"
id="ex3-listbox"
class="listbox hidden">
</ul>
</div>
combobox design pattern in WAI-ARIA Authoring Practices 1.1
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK