Skip to content

GhostListbox ​

GhostListbox is a visible list where one or more rows are the current selection and the user moves through the rows with the keyboard: a mail message list beside a reading pane, a list of files or saved views, or a picker panel that stays open on the page. It follows the WAI-ARIA APG listbox pattern: one Tab stop, arrow, Home / End, and typeahead movement, single or multiple selection with the APG multi-select keys, desktop-style pointer selection, and a supported route to a context menu on a row.

Import GhostListbox, GhostListboxOption, GhostListboxGroup, and GhostListboxLabel from @ghostvue/themes for styled rows. The advanced section uses the same interface from @ghostvue/vue.

Read mail with a reading pane ​

Mail list

Themed inbox with a reading pane: selection follows focus, Archive and Delete in a toolbar and in a row context menu, and focus recovery after a delete.

Inbox

Billing: Invoice 4821Your November invoice is ready to download. Nov 30
Build bot: Nightly build passedAll 1,284 checks passed on main in 14 minutes. Nov 29
Design review: Header spacingCan we tighten the gap under the page title? Nov 28
Billing: Receipt 4790Thanks, we received your payment. Nov 27
Support: Ticket 311 resolvedThe export timeout is fixed in today’s release. Nov 26

Invoice 4821

From Billing · Nov 30

Your November invoice is ready to download.

Press Shift+F10 or the Menu key for message actions.

The inbox above imports from @ghostvue/themes. It uses selection-follows-focus, so Down Arrow, End, and typing a sender's first letter move the selection and the reading pane follows. Archive and Delete live in the toolbar above the list and in a context menu on the row: right-click a message, or focus it and press Shift+F10 or the Menu key. After a delete, focus moves to the next message.

vue
<GhostToolbar label="Message actions">
  <GhostButton :disabled="!selected" @click="archive(selected)">Archive</GhostButton>
</GhostToolbar>
<GhostContextMenu>
  <GhostContextMenuTrigger as="div" focus-target="descendant">
    <GhostListbox v-model="selected" aria-labelledby="inbox-heading" aria-describedby="inbox-hint">
      <GhostListboxOption v-for="message in messages" :key="message.id" :value="message.id">
        …
      </GhostListboxOption>
    </GhostListbox>
  </GhostContextMenuTrigger>
  <GhostContextMenuContent>
    <GhostContextMenuItem @select="archive(selected)">Archive</GhostContextMenuItem>
  </GhostContextMenuContent>
</GhostContextMenu>

Select several messages ​

Mail list with multiple selection

Themed inbox with desktop-style replace selection, Shift and Ctrl/Cmd clicks, a selection count live region, and toolbar and context menu actions on the selection.

Triage

Billing: Invoice 4821Nov 30
Build bot: Nightly build passedNov 29
Design review: Header spacingNov 28
Billing: Receipt 4790Nov 27
Support: Ticket 311 resolvedNov 26

Shift+click selects a range and Ctrl+click (Cmd+click on macOS) adds a row. Press Shift+F10 or the Menu key for actions.

0 messages selected.

multiple makes the model a string[]. With selection-behavior="replace", a plain click selects only that row as in a desktop mail client, Shift+click selects a range, and Ctrl+click (Cmd+click on macOS) adds or removes one row. Touch has no modifiers, so the Select button switches plain taps to the default toggle behavior. The polite status line announces the selection count, because range and select-all changes are not announced row by row.

Pick several options ​

Multiple selection

Themed multiple listbox with the default toggle behavior: click, tap, or Space adds and removes options.

Toppings

Basil
Mozzarella
Mushroom
Olive
Roasted pepper

Selected: basil

The default selection-behavior="toggle" adds or removes a row on click, tap, or Space, like a multiple GhostSelect. The model keeps selection order: a new value is appended, and a range or select-all appends the new values in rendered order.

Group options ​

Groups

Themed listbox of saved views in labelled groups, with a disabled option skipped by the arrow keys.

Pinned
My open issues
Waiting for my review
Team
Needs triage
Archived board
Release blockers

GhostListboxGroup renders role="group" named by the GhostListboxLabel inside it. Labels are not focusable. Disabled options are skipped by the arrow keys, typeahead, ranges, and Ctrl+A.

Lay options out in a row ​

Horizontal

Themed horizontal listbox where ArrowLeft and ArrowRight follow reading direction, with a right-to-left switch.

XS
S
M
L
XL

Size: M

orientation="horizontal" moves focus with Left Arrow and Right Arrow in reading order, flipped under dir="rtl".

When to use something else ​

NeedUse
A value picked from a popup, or submitted with a formGhostSelect (or GhostCombobox to filter by typing)
One choice from a few, always visible, inside a formGhostRadioGroup
Several independent checkboxes in a formGhostCheckboxGroup
Nested items with expand and collapseGhostTree
Rows with cells, or buttons and inputs inside rowsGhostDataGrid
A focus-only composite with no selectionuseRovingFocus

The listbox has no name and renders no hidden inputs. Forms submit the model themselves or use the form controls above.

Selection ​

  • Single mode. v-model is string | undefined. Clicking the selected option, or pressing Space on it, keeps it selected and emits nothing; clear the selection in code by setting undefined.
  • Multiple mode. v-model is string[], never undefined. The listbox never mutates the array you pass, emits a new array for every change, and tolerates frozen arrays.
  • One emit per gesture. A range, Shift+click, or Ctrl+A emits once with the whole new array. A gesture that changes nothing emits nothing.
  • Hidden rows. Filtering or removing an option never removes its value from the model. Toggles, ranges in toggle behavior, and Ctrl+A keep values whose option is not mounted; a replacing gesture (a plain or Shift+click with replace, or opening the context menu on an unselected row) drops them, so an action never reaches rows the user cannot see. To make "delete removes from the selection" true, update the model in the same handler that removes the data.
  • Consumer shortcuts. Your @keydown, @click, and @contextmenu listeners on the root or an option run first. Call preventDefault() to skip the listbox's handling, for example to open a message on Enter or delete it on Delete.

Row actions and context menus ​

Options cannot contain buttons, so row actions take two routes:

  1. A visible control outside the list that acts on the selection (a toolbar or a menu button). Every action in a row's context menu must also be here. It is the route that works for every user, including keyboards with no Menu key on macOS and touch screen reader users.
  2. A context menu on the row, as a shortcut. Wrap the listbox in GhostContextMenuTrigger with focus-target="descendant". The wrapper is not a tab stop, the menu opens for the option under the pointer or the focused option, and focus returns to that option on close.

When the menu opens on an option that is not selected, the selection becomes that option; on a selected option the whole selection is kept. So the menu always acts on the selection and always includes the row it was opened on. In multiple mode, opening it from the keyboard on an unselected row collapses a multi-row selection to that row; announce the new count in a live region, as the mail examples do. Disabled options, group labels, the list's padding, an empty list, and a disabled list do not open the menu.

A short hint such as "Press Shift+F10 or the Menu key for message actions" can be referenced with aria-describedby on the listbox. It is a supplement: screen readers do not reliably read a listbox description when focus lands on an option.

Keyboard ​

Keys act on the focused option. On macOS, Cmd takes the place of Ctrl in every Ctrl chord. Unlisted chords and keys that belong to an IME composition are left to the browser.

KeySingle modeMultiple mode
Tab / Shift+TabEnter or leave the list through its one tab stop.Same.
Down Arrow / Up ArrowFocus the next or previous enabled option.Same; the selection does not change.
Home / EndFocus the first or last enabled option.Same.
Printable charactersTypeahead on textValue (500 ms buffer).Same.
SpaceSelect the focused option.Toggle it and set the range anchor.
EnterSelect the focused option.Not handled; use it for your own action.
Shift+Down Arrow / Up ArrowSame as without Shift.Move and toggle the newly focused option.
Shift+SpaceNot handled.Select from the anchor to the focused option.
Ctrl+Shift+Home / EndNot handled.Select to the first or last option and focus it.
Ctrl+ANot handled.Select every enabled option, or deselect them all.
Shift+F10 / MenuOpen the row's context menu inside a descendant-mode trigger.Same.
EscapeNot handled, so an enclosing dialog closes.Same.

With selection-follows-focus in single mode, arrows, Home / End, and typeahead also select. loop wraps the arrow keys.

Pointer ​

A click or tap focuses the option without a visible ring and then:

GestureSingleMultiple, toggleMultiple, replace
Click or tapSelect it.Toggle it.Select only it.
Ctrl / Cmd+clickSelect it.Toggle it.Toggle it.
Shift+clickSelect it.Add the range from the anchor.Replace the selection with the range.

Shift+click does not select page text. On macOS Ctrl+click is a secondary click and opens the context menu.

Focus and removal ​

Before the user moves in the list, the tab stop is the first selected enabled option, else the first enabled option. An empty or disabled list is itself the tab stop, so Tab still reaches its name. When options are removed, the tab stop moves to the option that followed the removed one (even if the same update moved it), else the one before it; an option inserted in its place in the same update comes first. If the removed option had focus, focus moves too. Recovery never changes the selection.

focusOption(value) on a template ref moves the tab stop and focus to an option without selecting it, and returns false for a missing or disabled option.

Server rendering ​

Server HTML carries the roles, aria-selected from the initial model, and ids from useGhostId. The selected option (or the first option when nothing is selected) renders tabindex="0"; a disabled root renders it on the root. A stale model value or an empty list renders no stop until the page hydrates. Hydration does not move focus.

Accessibility ​

  • Name the listbox with aria-label or aria-labelledby; a missing name logs a development warning.
  • An option's text is its accessible name. Put the words that identify a row first (for a message, the sender and subject), so screen readers read them first, and use text-value to make typeahead match them.
  • Options may not contain buttons, links, inputs, or other focusable controls. Use GhostDataGrid for rows with in-row controls.
  • Selection changes on the focused option are announced through aria-selected. Announce bulk changes, such as "12 messages selected", in your own polite live region.
  • Scrolling is yours: give the listbox, or a GhostScrollArea around it, a height and overflow: auto. Keyboard movement keeps the focused option in view.

Advanced: headless composition ​

For teams that bring their own design system, the same parts ship unstyled from @ghostvue/vue. Style them through data-part (listbox, option, group, label), aria-selected or data-state="checked", data-disabled, and :focus-visible.

Basic Headless

Headless single-selection listbox with consumer CSS on the data-part and aria-selected hooks.

US East
US West
EU Central
Asia Pacific South

Deploying to us-east

API ​

See the generated component references for props, emits, slots, exposed members, and styling hooks.

PropTypeDefaultDescription
asGhostListboxElement"div"Host element. Options inside a ul / ol root use as="li"; groups are supported only with the default div.
defaultValueGhostListboxValueInput<Multiple>—Initial selection in uncontrolled mode. Copied at setup.
disabledbooleanfalseDisables every option. The selection stays visible and unchanged.
loopbooleanfalseArrow keys wrap from the last option to the first and back.
modelValueGhostListboxValueInput<Multiple>—Controlled selection. undefined is uncontrolled.
multipleMultiple—Multiple selection (string[] model). Read once at setup.
orientationGhostListboxOrientation"vertical"Which arrow keys move focus. Horizontal arrows follow reading direction.
selectionBehaviorGhostListboxSelectionBehavior"toggle"Multiple mode only: what a plain click or tap does.
selectionFollowsFocusbooleanfalseSingle mode only: arrow keys, Home / End, and typeahead also select the newly focused option.
SlotSlot propsDescription
defaultactiveValue: string | undefined, selectedValues: readonly string[]GhostListboxOption and GhostListboxGroup children.

@ghostvue/themes adds no props, events, or slots to the headless GhostListbox API, which it forwards.

GhostListboxOption ​

PropTypeDefaultDescription
asstring"div"Host element. Use li inside a ul / ol root.
disabledbooleanfalseThe option cannot be focused or selected.
textValuestring—Text used for typeahead; defaults to the trimmed text content.
valuestringRequiredIdentity of the option. Unique within the root; '' is unsupported.
SlotSlot propsDescription
defaultactive: boolean, disabled: boolean, focused: boolean, selected: booleanOption content; receives selected, disabled, active, and focused.

GhostListboxGroup and GhostListboxLabel ​

GhostListboxGroup takes as (default div) and renders role="group" labelled by its GhostListboxLabel. Groups cannot be nested and are supported only with the default div root.

Specification ​

See the GhostListbox specification.