(Deprecated) Collapsible Dropdown Listbox Example
DEPRECATION WARNING: This pattern has been deprecated, and will be removed in a future version of the ARIA Authoring Practices. The select-only combobox should be used as an alternative to this pattern.
The following example implementation of the
설계 패턴 for listbox
demonstrates a collapsible single-select listbox widget that is functionally similar to an HTML select
input with the attribute size="1"
.
The widget consists of a button that triggers the display of a listbox.
In its default state, the widget is collapsed (the listbox is not visible) and the button label shows the currently selected option from the listbox.
When the button is activated, the listbox is displayed and the current option is focused and selected.
유사한 예는 다음과 같습니다:
- Select-Only Combobox: HTML
select
엘리먼트와 기능적으로 유사한 텍스트 입력이 없는 선택 전용 콤보박스. - Scrollable Listbox Example: Single-select listbox that scrolls to reveal more options, similar to HTML
select
withsize
attribute greater than one. - Example Listboxes with Rearrangeable Options: Examples of both single-select and multi-select listboxes with accompanying toolbars where options can be added, moved, and removed.
- Listbox Example with Grouped Options: Single-select listbox with grouped options, similar to an HTML
select
withoptgroup
children.
Example
Choose your favorite transuranic element (actinide or transactinide).
- Neptunium
- Plutonium
- Americium
- Curium
- Berkelium
- Californium
- Einsteinium
- Fermium
- Mendelevium
- Nobelium
- Lawrencium
- Rutherfordium
- Dubnium
- Seaborgium
- Bohrium
- Hassium
- Meitnerium
- Darmstadtium
- Roentgenium
- Copernicium
- Nihonium
- Flerovium
- Moscovium
- Livermorium
- Tennessine
- Oganesson
Notes
This listbox is scrollable; it has more options than its height can accommodate.
-
Scrolling only works as expected if the listbox is the options'
offsetParent
. The example usesposition: relative
on the listbox to that effect. - When an option is focused that isn't (fully) visible, the listbox's scroll position is updated:
- If Up Arrow or Down Arrow is pressed, the previous or next option is scrolled into view.
- If Home or End is pressed, the listbox scrolls all the way to the top or to the bottom.
- If
focusItem
is called, the focused option will be scrolled to the top of the view if it was located above it or to the bottom if it was below it. - If the mouse is clicked on a partially visible option, it will be scrolled fully into view.
- When a fully visible option is focused in any way, no scrolling occurs.
키보드 지원
The example listbox 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 Listbox 설계 패턴.
키 | 기능 |
---|---|
Enter |
|
Escape | If the listbox is displayed, collapses the listbox and moves focus to the button. |
Down Arrow |
|
Up Arrow |
|
Home | If the listbox is displayed, moves focus to and selects the first option. |
End | If the listbox is displayed, moves focus to and selects the last option. |
Printable Characters |
|
Role, Property, State, Tabindex 어트리뷰트
The example listbox 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 Listbox 설계 패턴.
역할(role) | 어트리뷰트 | 엘리먼트 | 사용법 |
---|---|---|---|
aria-labelledby="ID_REF1 ID_REF2" |
button |
|
|
aria-haspopup="listbox" |
button |
Indicates that activating the button displays a listbox. | |
aria-expanded="true" |
button |
|
|
listbox |
ul |
Identifies the focusable element that has listbox behaviors and contains the listbox options. | |
aria-labelledby="ID_REF" |
ul |
Refers to the element containing the listbox label. | |
tabindex="-1" |
ul |
|
|
aria-activedescendant="ID_REF" |
ul |
|
|
option |
li |
Identifies each selectable element containing the name of an option. | |
aria-selected="true" |
li |
|
Javascript와 CSS 소스 코드
- CSS: listbox.css
- Javascript: listbox.js, listbox-collapsible, utils.js
HTML Source Code