Listbox Example
+Example Listboxes with Rearrangeable Options
- This example page is incomplete; it is not ready for review. - When ready, feedback will be welcome in issue 123. + NOTE: This example page is incomplete; it is not ready for final review. + Development is tracked by + issue 123.
The following two example implementations of the @@ -32,6 +33,10 @@
Listbox Example
In the first implementation, users can choose a single option and then activate an action button while in the second example, they may select multiple options before activating an action button. +Similar examples include:
+-
+
- Scrollable Listbox Example: Single-select listbox that scrolls to reveal more options, similar to HTML
select
withsize
attribute greater than one.
+
Examples
Notes
Example 3: Scrollable Listbox
- -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 example has a
listbox
with 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. -
- Normal scrolling through any scrolling mechanism (including Page Up and Page Down) works as expected.
- The scroll position will jump as described for
focusItem
if another means than a mouse click is used to change focus after scrolling.
- - This example uses a single-select listbox, but works just as well with a multi-select listbox. -
Accessibility Features
Keyboard Support
++ The example listboxes 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 Listbox Design Pattern. +
Down Arrow | -Moves focus to the next option. | +
+
|
---|---|---|
Up Arrow | -Moves focus to the previous option. | +
+
|
Home | -Moves focus to first option. | +
+
|
End | -Moves focus to last option. | +
+
|
Multiple selection keys supported in example 2
-Key | @@ -321,6 +291,11 @@
---|
Note>
-The following attributes are commonly useful when implementing the listbox design pattern but are not used in these examples.
--
-
aria-setsize
andaria-posinset
: Since all option elements are present in the DOM, the browser is able to calculate these values automatically and provide them to assistive technologies.
- aria-orientation
: The default orientation for a listbox is vertical so it is not necessary to specify a value.
-
Javascript and CSS Source Code
Javascript: listbox.js +Example 2: Multi-Select Listbox
- Example 3: Scrollable Listbox
- -
-
-
diff --git a/examples/listbox/listbox-scrollable.html b/examples/listbox/listbox-scrollable.html
new file mode 100644
index 0000000000..f292110cdf
--- /dev/null
+++ b/examples/listbox/listbox-scrollable.html
@@ -0,0 +1,236 @@
+
+
+
+
+Scrollable Listbox Example
++ Please provide feedback on this example in + issue 469. +
+
+ The following example implementation of the
+ design pattern for listbox
+ demonstrates a scrollable single-select listbox widget.
+ This widget is functionally similar to an HTML select
input where the size
attribute has a value greater than one.
+
Similar examples include:
+-
+
- 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. +
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. +
- Normal scrolling through any scrolling mechanism (including Page Up and Page Down) works as expected.
+ The scroll position will jump as described for
focusItem
if a means other than a mouse click is used to change focus after scrolling.
+
Keyboard Support
++ The example listboxes 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 Listbox Design Pattern. +
+Key | +Function | +
---|---|
Down Arrow | +
+
|
+
Up Arrow | +Moves focus to and selects the previous option. | +
Home | +Moves focus to and selects the first option. | +
End | +Moves focus to and selects the last option. | +
Role, Property, State, and Tabindex Attributes
++ The example listboxes 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 Listbox Design Pattern. +
+Role | +Attribute | +Element | +Usage | +
---|---|---|---|
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="0" |
+ ul |
+ Includes the listbox in the page tab sequence. | +
+ | aria-activedescendant="ID_REF" |
+ ul |
+
+
|
+
role="option" |
+ + | li |
+ Identifies each selectable element containing the name of an option. | +
+ | aria-selected="true" |
+ li |
+
+
|
+
Javascript and CSS Source Code
+-
+
- + CSS: + listbox.css + +
- + Javascript: + listbox.js + +
- + Javascript: + listbox-scrollable.js + +
HTML Source Code
+ +
+
+
+
+