Listbox

4 Listbox variations from the W3C ARIA Authoring Practices Guide.

Listbox (Collapsible, Deprecated)

This deprecated example is preserved for comparison. A button opens a separate listbox and displays its selected supply. Use the select-only combobox pattern for new interfaces.

Corresponding W3C APG example

W3C marks this example as deprecated. It is included for comparison; use the current alternative when building new interfaces.

Example

Deprecated pattern: prefer the select-only combobox.

Preferred supply
  • Canvas
  • Cardboard
  • Chalk
  • Clay
  • Copper
  • Cotton
  • Ink
  • Paper
  • Pencil
  • Ribbon
  • Thread
  • Wood

Keyboard interaction

Enter or Space on the button opens the list. Up/Down changes the selected option. Enter or Escape closes the list and returns focus to the button. Tab closes it and moves onward.

Events

Listen on the widget or delegate to <axxy-scope> or document. All custom events bubble.

  • axxy-listbox-change — Dispatched when the selected option(s) change. (target: [role="listbox"], detail: { selected: HTMLElement[] })

Events reference and examples

Example HTML

<axxy-scope>
  <p>
    <strong>Deprecated pattern:</strong>
    prefer the select-only combobox.
  </p>
  <span id="demo-collapse-label">Preferred supply</span>
  <button id="demo-collapse-trigger" aria-haspopup="listbox" aria-labelledby="demo-collapse-label demo-collapse-trigger">Canvas</button>
  <ul role="listbox" aria-labelledby="demo-collapse-label" style="max-height:12rem;overflow:auto;border:1px solid currentColor;padding:.5rem;list-style:none">
    <li>Canvas</li>
    <li>Cardboard</li>
    <li>Chalk</li>
    <li>Clay</li>
    <li>Copper</li>
    <li>Cotton</li>
    <li>Ink</li>
    <li>Paper</li>
    <li>Pencil</li>
    <li>Ribbon</li>
    <li>Thread</li>
    <li>Wood</li>
  </ul>
</axxy-scope>

Listbox (Grouped)

A single-select supply list organizes options under named studio departments. Arrow navigation crosses group boundaries without selecting group labels.

Corresponding W3C APG example

Example

Choose a studio supply

  • Chalk
  • Ink
  • Pencil
  • Cotton
  • Ribbon
  • Thread
  • Clay
  • Copper
  • Wood

Keyboard interaction

Focus stays on the listbox. Up/Down, Home/End, and typing letters move the active option into view. In a single-select list, selection follows the active option. Tab leaves the listbox.

Events

Listen on the widget or delegate to <axxy-scope> or document. All custom events bubble.

  • axxy-listbox-change — Dispatched when the selected option(s) change. (target: [role="listbox"], detail: { selected: HTMLElement[] })

Events reference and examples

Example HTML

<axxy-scope>
  <h3 id="demo-grouped-label">Choose a studio supply</h3>
  <div role="listbox" aria-labelledby="demo-grouped-label" style="max-height:12rem;overflow:auto;border:1px solid currentColor;padding:.5rem;list-style:none">
    <ul aria-label="Drawing">
      <li>Chalk</li>
      <li>Ink</li>
      <li>Pencil</li>
    </ul>
    <ul aria-label="Textiles">
      <li>Cotton</li>
      <li>Ribbon</li>
      <li>Thread</li>
    </ul>
    <ul aria-label="Sculpture">
      <li>Clay</li>
      <li>Copper</li>
      <li>Wood</li>
    </ul>
  </div>
</axxy-scope>

Listbox (Rearrangeable)

Rank workshop priorities with a single-select list, then choose multiple supplies and transfer them between lists. Actions preserve the active position and announce the change.

Corresponding W3C APG example

Example

Rank workshop priorities

Priorities

  • Natural light
  • Quiet workspace
  • Large tables
  • Tool storage

Set-aside priorities

    Choose workshop supplies

    Available supplies

    • Canvas
    • Chalk
    • Clay
    • Copper
    • Ink

    Chosen supplies

      Keyboard interaction

      Focus stays on the listbox. Up/Down, Home/End, and typing letters move the active option into view. In a single-select list, selection follows the active option. Tab leaves the listbox. In multi-select lists, Space toggles selection, Shift+arrows selects a range, and Control+A selects or clears all. Alt+Up/Down reorders priorities; Delete transfers a priority. Enter adds selected supplies and Delete removes them. Toolbar Left/Right moves between action buttons.

      Events

      Listen on the widget or delegate to <axxy-scope> or document. All custom events bubble.

      • axxy-listbox-change — Dispatched when the selected option(s) change. (target: [role="listbox"], detail: { selected: HTMLElement[] })
      • axxy-listbox-reorder — Dispatched when items are moved or reordered. (target: [role="listbox"], detail: { message: string })

      Events reference and examples

      Example HTML

      <axxy-scope>
        <section>
          <h2>Rank workshop priorities</h2>
          <h3 id="demo-priorities-label">Priorities</h3>
          <ul id="demo-priorities" role="listbox" aria-labelledby="demo-priorities-label"  style="max-height:12rem;overflow:auto;border:1px solid currentColor;padding:.5rem;list-style:none">
            <li>Natural light</li>
            <li>Quiet workspace</li>
            <li>Large tables</li>
            <li>Tool storage</li>
          </ul>
          <div role="toolbar" aria-label="Priority actions">
            <button type="button" aria-controls="demo-priorities" aria-keyshortcuts="Alt+ArrowUp">Move up</button>
            <button type="button" aria-controls="demo-priorities" aria-keyshortcuts="Alt+ArrowDown">Move down</button>
            <button type="button" aria-controls="demo-priorities demo-aside" aria-keyshortcuts="Delete">Set aside</button>
            <button type="button" aria-controls="demo-aside demo-priorities" aria-keyshortcuts="Delete">Restore priority</button>
          </div>
          <h3 id="demo-aside-label">Set-aside priorities</h3>
          <ul id="demo-aside" role="listbox" aria-labelledby="demo-aside-label"  style="max-height:12rem;overflow:auto;border:1px solid currentColor;padding:.5rem;list-style:none"></ul>
        </section>
        <section>
          <h2>Choose workshop supplies</h2>
          <h3 id="demo-available-label">Available supplies</h3>
          <ul id="demo-available" role="listbox" aria-labelledby="demo-available-label" aria-multiselectable="true" style="max-height:12rem;overflow:auto;border:1px solid currentColor;padding:.5rem;list-style:none">
            <li>Canvas</li>
            <li>Chalk</li>
            <li>Clay</li>
            <li>Copper</li>
            <li>Ink</li>
          </ul>
          <div role="toolbar" aria-label="Supply actions">
            <button type="button" aria-controls="demo-available demo-chosen" aria-keyshortcuts="Enter">Add supplies</button>
            <button type="button" aria-controls="demo-chosen demo-available" aria-keyshortcuts="Delete">Remove supplies</button>
          </div>
          <h3 id="demo-chosen-label">Chosen supplies</h3>
          <ul id="demo-chosen" role="listbox" aria-labelledby="demo-chosen-label" aria-multiselectable="true" style="max-height:12rem;overflow:auto;border:1px solid currentColor;padding:.5rem;list-style:none"></ul>
        </section>
        <p id="demo-selection-status" role="status" aria-live="polite"></p>
      </axxy-scope>

      Listbox (Scrollable)

      A long inventory uses a fixed-height listbox. Keyboard navigation scrolls the active option into view while DOM focus remains on the list.

      Corresponding W3C APG example

      Example

      Workshop inventory

      • Supply kit 01
      • Supply kit 02
      • Supply kit 03
      • Supply kit 04
      • Supply kit 05
      • Supply kit 06
      • Supply kit 07
      • Supply kit 08
      • Supply kit 09
      • Supply kit 10
      • Supply kit 11
      • Supply kit 12
      • Supply kit 13
      • Supply kit 14
      • Supply kit 15
      • Supply kit 16
      • Supply kit 17
      • Supply kit 18
      • Supply kit 19
      • Supply kit 20
      • Supply kit 21
      • Supply kit 22
      • Supply kit 23
      • Supply kit 24
      • Supply kit 25
      • Supply kit 26
      • Supply kit 27
      • Supply kit 28
      • Supply kit 29
      • Supply kit 30

      Keyboard interaction

      Focus stays on the listbox. Up/Down, Home/End, and typing letters move the active option into view. In a single-select list, selection follows the active option. Tab leaves the listbox.

      Events

      Listen on the widget or delegate to <axxy-scope> or document. All custom events bubble.

      • axxy-listbox-change — Dispatched when the selected option(s) change. (target: [role="listbox"], detail: { selected: HTMLElement[] })

      Events reference and examples

      Example HTML

      <axxy-scope>
        <h3 id="demo-inventory-label">Workshop inventory</h3>
        <ul id="demo-inventory" role="listbox" aria-labelledby="demo-inventory-label"  style="max-height:12rem;overflow:auto;border:1px solid currentColor;padding:.5rem;list-style:none">
          <li>Supply kit 01</li>
          <li>Supply kit 02</li>
          <li>Supply kit 03</li>
          <li>Supply kit 04</li>
          <li>Supply kit 05</li>
          <li>Supply kit 06</li>
          <li>Supply kit 07</li>
          <li>Supply kit 08</li>
          <li>Supply kit 09</li>
          <li>Supply kit 10</li>
          <li>Supply kit 11</li>
          <li>Supply kit 12</li>
          <li>Supply kit 13</li>
          <li>Supply kit 14</li>
          <li>Supply kit 15</li>
          <li>Supply kit 16</li>
          <li>Supply kit 17</li>
          <li>Supply kit 18</li>
          <li>Supply kit 19</li>
          <li>Supply kit 20</li>
          <li>Supply kit 21</li>
          <li>Supply kit 22</li>
          <li>Supply kit 23</li>
          <li>Supply kit 24</li>
          <li>Supply kit 25</li>
          <li>Supply kit 26</li>
          <li>Supply kit 27</li>
          <li>Supply kit 28</li>
          <li>Supply kit 29</li>
          <li>Supply kit 30</li>
        </ul>
      </axxy-scope>