GhostListbox specification
Important
Status: Approved on 2026-12-01 by zprue743 for 0.4.0 (see Approval). This spec defines a standalone, always-visible listbox: a list where a user selects a row by click or arrow keys and opens actions on it, as in a mail message list. It also adds one additive prop on GhostContextMenuTrigger, recorded as the composite trigger amendment in the context menu spec, approved with this spec.
Purpose and user problems
An application needs a visible list of items where one or more rows are the current selection, and the user moves through the rows with the keyboard. Typical surfaces are a mail message list beside a reading pane, a list of files or saved views, and a picker panel that stays open on the page.
Today GhostVue has listbox behavior only inside the GhostSelect and GhostCombobox popups. App builders who needed a visible selectable list used parts with the wrong semantics:
- a flat
GhostTree(announces a tree with levels), GhostDataTable(row clicks are not selection; a table is not a widget),GhostToggleGroup, or<GhostContextMenuTrigger :as="GhostToggleGroupItem">(works, but announces a group of toggle buttons and has no typeahead, range selection, oraria-selected),- a
<ul>of buttons with a hand-writtenj/khandler.
GhostListbox gives that surface 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.
Design recommendation
The design step compared four shapes for the mail-list task:
| Shape | Outcome |
|---|---|
listbox with option (chosen) | Matches the task: each row is one selectable item read as a whole. Screen readers announce position, selected state, and multi-select. Row actions live in a context menu and in toolbars outside the list. |
grid (GhostDataGrid) | Right for rows with cells the user moves between, or with buttons inside rows. It adds a second axis and cell-by-cell reading that a message list does not need. Consumers who need in-row controls already have GhostDataGrid. |
Compose from useRovingFocus | Gives roving tabindex only. The consumer would still write role, aria-selected, aria-multiselectable, typeahead, range selection, SSR tab stop, focus recovery after removal, and the context-menu handoff. That is the component this spec defines. |
Flat GhostTree or GhostToggleGroup | Wrong roles. A tree announces levels and expansion; a toggle group announces pressed buttons and has no multi-select range keys. |
Recommendation: ship GhostListbox as a new headless component with a themed recipe. The build reuses internal Select helpers where it can without changing Select or Combobox behavior (see Composition).
Non-goals
- Popup listboxes.
GhostSelectandGhostComboboxkeep their own listbox parts. This spec does not change their public behavior or exports. - Interactive content inside options. An
optionmay not contain buttons, links, inputs, or other focusable controls. UseGhostDataGridfor rows with in-row controls. - Virtualized lists, drag reordering, and lazy loading. Every option the user can reach is mounted. Infinite scroll is the consumer's, outside the listbox contract.
- Native form submission. The listbox has no
nameand renders no hidden inputs. Forms useGhostSelect,GhostCheckboxGroup, orGhostRadioGroup, or submit the model themselves. - Filtering or a search input. A filter field outside the list that changes which options render is supported (see Consumer data); a built-in combobox input is not.
- Activation events. There is no
activate/actionevent forEnteror double-click. Consumers add their ownkeydownordblclickhandler on the option (see Events). - Nested lists and hierarchy. Use
GhostTree. - Automatic
aria-keyshortcutson options. See Assistive technology expectations.
Public API
Parts and exports
Headless exports from @ghostvue/vue:
GhostListbox: root,role="listbox", owns selection and keyboard.GhostListboxOption:role="option".GhostListboxGroup:role="group", labelled by itsGhostListboxLabel.GhostListboxLabel: the visible label of a group. Not focusable.- Types:
GhostListboxProps,GhostListboxOptionProps,GhostListboxModelValue<Multiple>,GhostListboxValueInput<Multiple>,GhostListboxSelectionBehavior,GhostListboxOrientation,GhostListboxExposed,GhostListboxOptionExposed.
The themed package (@ghostvue/themes) wraps the same four parts with the ghost-listbox recipe, as other themed components do. There is no composable export in 0.4.0; see Open architectural questions.
Props and configuration
GhostListbox (root)
| Prop | Type | Default | Contract |
|---|---|---|---|
modelValue | GhostListboxValueInput<Multiple> | undefined | undefined | Controlled selection. string in single mode, readonly string[] in multiple mode. undefined means uncontrolled. |
defaultValue | GhostListboxValueInput<Multiple> | undefined | undefined | Initial selection in uncontrolled mode. Copied at setup. |
multiple | Multiple extends boolean | false | Multiple selection. Fixed at setup, as in GhostSelect; a later change logs a development warning and is ignored. |
selectionFollowsFocus | boolean | false | Single mode only. When true, arrow keys, Home / End, and typeahead also select the newly focused option. Ignored in multiple mode with a development warning. |
selectionBehavior | 'toggle' | 'replace' | 'toggle' | Multiple mode only: what a plain click or tap does. toggle adds or removes the option. replace makes it the only selected option. Modifier clicks are the same in both (see Pointer). |
orientation | 'vertical' | 'horizontal' | 'vertical' | Which arrow keys move focus. Rendered as aria-orientation. Horizontal arrows follow reading direction in RTL. |
loop | boolean | false | Wrap from the last option to the first and back with the arrow keys. Home / End are unaffected. |
disabled | boolean | false | Disables every option. The selection stays visible and unchanged. |
Multiple is inferred from the template with <script setup lang="ts" generic="Multiple extends boolean = false">, exactly as GhostSelect does. The type table and the rejected forms in the Select type inference contract apply with GhostListbox in place of GhostSelect:
export type GhostListboxValueInput<Multiple extends boolean = false> =
Multiple extends true ? readonly string[] : string
export type GhostListboxModelValue<Multiple extends boolean = false> =
Multiple extends true ? string[] : string | undefined
export type GhostListboxSelectionBehavior = 'toggle' | 'replace'
export type GhostListboxOrientation = 'vertical' | 'horizontal'The listbox must have an accessible name: aria-label or aria-labelledby on the root, both passed through as attributes. A root without either logs a development warning on mount (a new GHOST0xx code allocated by the build).
GhostListboxOption
| Prop | Type | Default | Contract |
|---|---|---|---|
value | string | required | Identity of the option. Unique within the root. '' is unsupported, as in GhostSelect. |
textValue | string | undefined | text content | Text used for typeahead. Defaults to the option's trimmed textContent at mount and after content updates. |
disabled | boolean | false | The option cannot be focused by keys or pointer and cannot be selected. A selected disabled option stays selected. |
as | string | 'div' | Host element. li is allowed when the root renders as ul. Any element keeps role="option". |
GhostListbox host element
The root renders a div by default and takes as ('div' | 'ul' | 'ol'). Options inside a ul / ol root use as="li". Roles are set explicitly, so list semantics from the native elements are replaced. Groups are supported only with the default div root: a GhostListboxGroup inside a ul / ol root logs a development warning, because it would render a div child of a list element.
GhostListboxGroup and GhostListboxLabel
GhostListboxGroup renders role="group" with aria-labelledby pointing at the id of the GhostListboxLabel inside it. A group without a label logs a development warning and should get aria-label. Groups cannot be nested and are not focusable. GhostListboxLabel renders a div with no role.
v-model contracts
- Single mode.
v-modelisstring | undefined. Selecting an option emits itsvalue. The user cannot clear a single selection through the listbox: clicking the selected option, or pressingSpaceon it, keeps it selected and emits nothing. The consumer clears it by settingundefined: oncemodelValuehas been defined, a laterundefinedis a controlled empty selection, not a switch to uncontrolled mode (useControllableStatewithallowControlledUndefined, asGhostTreeandGhostToggleGroupdo). - Multiple mode.
v-modelisstring[]. Neverundefinedin emitted values; the empty selection is[]. - Ownership. The collection rules from the Select spec apply unchanged: the listbox never mutates the array it receives, every emit is a new array, duplicates in a controlled model count once and are not normalized by an emit, and the model keeps selection order (Select S2). A range or select-all that adds several values appends the newly added ones in rendered option order.
- Replacing gestures. A gesture that replaces the selection sets the model to exactly its new members and drops every other value, including values whose option is not mounted: a plain or
Shift+clickwithselectionBehavior: 'replace', and the context-menu selection rule when it replaces. A replacing range emits the range in rendered option order. This keeps a filtered-out row from staying silently selected under a row the user just picked, so an action on the selection never reaches rows the user cannot see. - Timing. One
update:modelValueper user gesture, emitted synchronously during the gesture's event handler. A range (Shift+click,Shift+Space,Ctrl+Shift+End) orCtrl+Aemits once with the whole new array. A gesture that does not change the selection emits nothing. - Controlled rejection. A parent that keeps its value rejects the change;
aria-selectedanddata-statefollow the parent's value after the next render.
Events, slots, and exposed methods
- Events.
update:modelValueonly. Pointer selection is applied on theclickevent (so a scroll gesture on touch never selects). ConsumeronKeydown,onClick,onPointerdown, andonContextmenulisteners on the root or an option run before the listbox's own handling. If a listener callsevent.preventDefault(), the listbox skips its handling of that event. This is the supported route for app shortcuts (j/k,Delete,Enterto open a message). - Slots. Default slot on every part. The root's default slot receives
{ selectedValues: readonly string[], activeValue: string | undefined }, whereactiveValueis the value of the tab-stop option whether or not DOM focus is inside the list (undefinedwhen the root is the tab stop). The option's default slot receives{ selected: boolean, disabled: boolean, active: boolean, focused: boolean }:activemeans it is the tab stop,focusedmeans it holds DOM focus. - Exposed on the root (
GhostListboxExposed):element: HTMLElement | nullfocus(options?: FocusOptions): voidfocuses the current tab stop (see Focus behavior).focusOption(value: string, options?: FocusOptions): booleanmoves the tab stop and DOM focus to that option and scrolls it into view (block: 'nearest') unlessoptions.preventScrollistrue. Returnsfalseand does nothing if the option is not mounted or is disabled. It never changes the selection, even withselectionFollowsFocus.
- Exposed on an option (
GhostListboxOptionExposed):element,focus,blur, as other parts expose.
State model
| State | Owner | Changes when |
|---|---|---|
| Selection | modelValue (controlled) or an internal copy | User selection gestures, selectionFollowsFocus movement, context-menu selection, the parent. |
| Active option | Listbox reactive state (the tab stop) | Arrow keys, Home / End, typeahead, pointer, focusOption, focus recovery. |
| Selection anchor | Internal | Plain or Ctrl / Cmd click, Space, context-menu selection. Read by range gestures. |
| Typeahead buffer | Internal | Printable keys; cleared 500 ms after the last one, on blur, and on any non-printable key. |
Active versus selected. The active option is the tab stop. The listbox keeps it in reactive state and renders tabindex itself (0 on the active option, -1 on the rest), as GhostTree does with its tab stop; while focus is in the list, the active option holds DOM focus. There is no aria-activedescendant. Selected options carry aria-selected="true". The two are independent except when selectionFollowsFocus is on in single mode, and for the context-menu selection rule.
Anchor. The anchor is the option the next range extends from. It starts as the first selected option in rendered order, else the first enabled option. Only a plain, Ctrl, or Cmd click, Space, and the context-menu selection rule set it. Shift+Arrow, Shift+click, Shift+Space, Ctrl+A, and Ctrl+Shift+Home / End leave it unchanged. If the anchor unmounts, the next range starts from the active option.
Loading, empty, disabled, read-only, and error states
- Empty. With no enabled options, the root itself becomes the tab stop (
tabindex="0"), soTabstill reaches the named, empty list. Consumers render empty text outside the listbox, because a listbox may only contain options and groups, and may reference it witharia-describedbyon the root. When an enabled option mounts, the root drops itstabindexand the option becomes the tab stop. If the root had focus at that moment, focus moves to that option. - Disabled root. Every option gets
aria-disabled="true"andtabindex="-1". The root getsaria-disabled="true"and becomes the tab stop (tabindex="0"), as in the empty case, so keyboard users can still reach the list, hear its name and disabled state, and scroll it with the arrow and page keys (the browser's default scrolling; the listbox handles no keys while disabled). Pointer and keys change nothing. The selection still renders. - Disabled option. Skipped by arrows,
Home/End, typeahead, range, andCtrl+A. A click or right-click on it does nothing (no focus change, no selection change, no context menu). - Loading. Not a listbox state. A consumer that loads options shows a loading indicator outside the list and may set
aria-busy="true"on the root, which passes through. - Read-only and error. Not supported states. A read-only list is a
disabledlistbox or plain content.
Async behavior
The listbox has no async operations. Context-menu actions that change the data (delete, move) happen in the consumer; the listbox reacts through focus recovery.
Consumer data
- Options are slot children. There is no
itemsprop. Consumers renderGhostListboxOptionin av-forwith a stablekey. Order, keyboard order, "first", "last", ranges, and typeahead all follow rendered DOM order, not registration order, as inGhostSelect. - Values are strings. Consumers map object identity to a string key (for example
message.id). - Values without a mounted option. Unmounting an option (filtering, conditional rendering, removal by the consumer) never removes its value from the model and never emits. Additive and subtractive gestures (toggles,
Shift+Arrow,Shift+Space,Ctrl+Shift+Home/End,Shift+clickwithselectionBehavior: 'toggle', andCtrl+A) act on mounted options only and keep unmounted members. Replacing gestures drop them. When the option mounts again it shows as selected without an emit. A consumer that wants "delete removes from selection" updates the model in the same handler that removes the data. - Duplicate option values are a consumer error. The first option in rendered order owns the value; later duplicates render, are not selectable, and log a development warning.
- No mutation. The listbox never mutates the model array or any consumer data, and tolerates frozen arrays.
Accessibility contract
Semantics and relationships
| Element | Attributes |
|---|---|
GhostListbox | role="listbox", consumer name (aria-label / aria-labelledby), aria-orientation, aria-multiselectable="true" in multiple mode only, aria-disabled="true" when disabled, tabindex="0" only when it is the tab stop of an empty or disabled list. data-part="listbox". |
GhostListboxOption | role="option", id, aria-selected="true" or "false" on every option in both modes, aria-disabled="true" when disabled, tabindex rendered by the listbox (0 on the active option, -1 elsewhere). data-part="option". |
GhostListboxGroup | role="group", aria-labelledby → its label's id. data-part="group". |
GhostListboxLabel | id, no role. data-part="label". |
The option's accessible name is its text content unless the consumer passes aria-label or aria-labelledby. A rich row keeps its full text as the name, so speech-input users can say any visible word of it. Put the words that identify the row first in DOM order (for a mail row, sender and subject before the snippet and date), so screen readers start with them, and set textValue so typeahead matches them. A shorter aria-labelledby name with an aria-describedby description is allowed but not required. The documentation and the mail-list example show the full-text pattern.
Keyboard interaction
Keys act on the focused option. Keys that belong to an active IME composition (isComposing, or keyCode 229) are ignored, as in GhostSelect. Alt chords are never handled. On macOS, Cmd takes the place of Ctrl in every Ctrl chord below, and Ctrl chords are not handled there. Any chord not listed (for example Ctrl+Arrow, Ctrl+Home, or Shift+Home / Shift+End in multiple mode) is not handled and not default-prevented, so it stays with the browser, the operating system, or assistive technology. Modifier-only keydowns (Shift, Ctrl, Meta, Alt) do not clear the typeahead buffer.
Movement (both modes). Vertical orientation shown; horizontal uses ArrowLeft / ArrowRight in reading order.
| Key | Behavior |
|---|---|
ArrowDown / ArrowUp | Focus the next or previous enabled option. At the ends, stay put unless loop. The newly focused option scrolls into view (block: 'nearest'). |
Home / End | Focus the first or last enabled option. |
| Printable characters | Typeahead: the buffer accumulates for 500 ms and focus moves to the next option whose textValue starts with it, using the shared findTypeaheadMatch rules. Space is part of the query while the buffer is not empty. |
Tab / Shift+Tab | Leave the listbox. Not handled. |
Escape | Not handled and not default-prevented, so an enclosing dialog or drawer still closes. |
Single mode.
| Key | Behavior |
|---|---|
Space / Enter | Select the focused option. No change if it is already selected. Default-prevented. |
| Movement keys | With selectionFollowsFocus, also select the newly focused option. Otherwise focus only. |
Shift + movement | Same as the key without Shift. |
Ctrl+A | Not handled. |
A consumer who wants Enter to open the message instead registers @keydown on the option and calls preventDefault() for Enter.
Multiple mode (APG multi-select listbox, "recommended" model; movement keys never change the selection on their own):
| Key | Behavior |
|---|---|
Space | Toggle the focused option. Sets the anchor. Default-prevented. |
Enter | Not handled, so consumer keydown handlers can use it. |
Shift+ArrowDown / Shift+ArrowUp | Move focus to the next or previous enabled option and toggle its selection. Does not move the anchor. |
Shift+Space | Select every enabled option from the anchor to the focused option, inclusive. Options already selected stay selected. |
Ctrl+Shift+Home / Ctrl+Shift+End | Select every enabled option from the focused option to the first or last, and move focus there. |
Ctrl+A | Select every enabled mounted option. If every enabled mounted option is already selected, deselect them all. Default-prevented. |
Shift+Space while the typeahead buffer is not empty is part of the query.
Pointer interaction
A primary click or tap on an enabled option focuses it (without a visible focus ring, through :focus-visible) and then, on the click event:
| Gesture | Single mode | Multiple, selectionBehavior: 'toggle' | Multiple, selectionBehavior: 'replace' |
|---|---|---|---|
| Click / tap | Select it. | Toggle it. Sets the anchor. | Select only it. Sets the anchor. |
Ctrl / Cmd + click | Select it. | Toggle it. Sets the anchor. | Toggle it. Sets the anchor. |
Shift + click | Select it. | Select the range from the anchor. | Replace the selection with the range from the anchor. |
Shift+click does not extend the browser's text selection inside the list.
On macOS, Ctrl+click is a secondary click: the browser fires contextmenu and no click, so it follows the context-menu path and never toggles. The toggle modifier on macOS is Cmd. On other platforms Ctrl+click toggles and Cmd does not exist.
Row actions and context menus
Options cannot contain buttons, so row actions have two routes:
- A visible control outside the list that acts on the selection (a toolbar or a menu button). This route is required whenever row actions exist: every action offered in a row's context menu must also be available here. It is the route that works for every user, including macOS keyboards with no
ContextMenukey, touch screen reader users, and anyone who does not discover the context menu. - A context menu on the row, as a shortcut. The supported composition wraps the listbox in a context menu trigger in composite mode:
<GhostToolbar aria-label="Message actions">
<GhostButton :disabled="!selected" @click="archive(selected)">Archive</GhostButton>
<GhostButton :disabled="!selected" @click="remove(selected)">Delete</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>
<GhostContextMenuItem @select="remove(selected)">Delete</GhostContextMenuItem>
</GhostContextMenuContent>
</GhostContextMenu>
<p id="inbox-hint" class="ghost-visually-hidden">
Press Shift+F10 or the Menu key for message actions.
</p>focus-target="descendant" is the additive GhostContextMenuTrigger prop in the composite trigger amendment. In that mode the wrapper is not a tab stop and carries no aria-haspopup (which listbox and option do not support). The trigger asks the listbox, through an internal before-open handshake, which element the menu is for, and returns focus there on close.
Context-menu selection rule. The rule runs inside the handshake, on every open path of the nearest enclosing focusTarget="descendant" trigger: right-click (contextmenu), long-press (when the trigger's timer fires, using the option under the original pointerdown), and the Shift+F10 / ContextMenu keys (using the focused option). It runs after the trigger's own disabled and defaultPrevented checks, so a disabled trigger or a consumer that cancels the event leaves the selection untouched. For an enabled option the listbox:
- makes that option active and focuses it (a no-op for keyboard opening, which starts on the focused option),
- if the option is not selected, replaces the selection with that option (one
update:modelValue) and sets it as the anchor, - if the option is selected, keeps the whole selection,
- returns the option as the menu's restore target, and the menu opens.
So the menu acts on the current selection, which includes the row the user opened it on unless a controlled parent rejected the change. Consumer menu items read the model. This matches file managers and desktop mail clients.
The listbox vetoes the open, so the menu does not open and the browser's default menu is not suppressed, when the target is a disabled option, a group label, the listbox's padding outside any option, the root of an empty list, or any part of a disabled listbox. A veto changes neither focus nor the selection.
When the trigger reports that a long-press opened the menu, the listbox ignores the click that may follow when the finger lifts, so the long-press does not also toggle or replace the selection.
A listbox inside a focusTarget="self" trigger does not take part in the handshake and logs a development warning, because the trigger would steal focus from the option. Outside any context menu trigger, the listbox ignores contextmenu entirely.
Focus behavior
Entry. One
Tabstop: the active option. Before the user has moved in the list, the active option is the first selected enabled option in rendered order, else the first enabled option, else the root (empty or disabled list). After that it is the last option the user,focusOption, or removal recovery made active, while it stays mounted and enabled.Server render and first paint. See SSR and hydration for which element carries
tabindex="0"before mount.Removal. When options unmount, the active option is recomputed after the DOM update (
nextTick). If it is gone, the new active option is anchored on the removed option's neighbors by identity, not by index, so a single update that also inserts or reorders options lands where the user was heading. An option is new when it was not rendered before the update; a keyed replacement in place counts as a new option at that slot. Let S be the first option that followed the removed one in the previous rendered order and is still mounted.- If new options sit contiguously just before S in the new order, the first enabled one of them. Otherwise S, then the options after it if S is disabled (and, if none of those is enabled, the nearest enabled option before them).
- If no successor survives, the same rule after the nearest surviving predecessor P: the first enabled new option directly after P, otherwise P (then the nearest enabled option before it).
- Otherwise no option is made active, so the entry rule picks the tab stop, which is the root when no option is enabled.
For example, with
bfocused:[a, b, d]→[a, c, d]lands onc,[a, b, c]→[c, a]lands onc, and[a, b]→[a, c]lands onc. This covers removing several options at once, such as a bulk delete of the selection. If the removed option held DOM focus, focus moves to the new active option in that same tick. Recovery never changes the selection, even withselectionFollowsFocus. If focus was elsewhere, only the tab stop moves.Return from a context menu. The menu returns focus to the option it was opened on. If that option was removed by the menu action, the trigger waits for the DOM update and then asks the listbox, through the same handshake registration, to focus its current active option, which the removal rule has moved by then (see the amendment's restore rule). When asked to restore, the listbox first applies any pending removal recovery synchronously against the mounted options and then focuses the result, so the order of the two after-update callbacks does not matter.
Disabled options never receive focus from keys or pointer.
Visible focus uses
:focus-visibleon the option. Pointer focus does not show a ring.
Assistive technology expectations
- Entering the list announces its name, "list box", the focused option's name, its selected state, and its position ("3 of 12"). In multiple mode screen readers also announce that the list is multi-select.
- Moving focus announces the new option. With
selectionFollowsFocus, it is announced as selected. - Toggling announces "selected" / "not selected" through the
aria-selectedchange on the focused option. No live region is added. Range andCtrl+Achanges are not announced option by option; a consumer that wants a count ("12 messages selected") renders it in its own polite live region, as the mail example does. - Row actions are always reachable through the required visible control outside the list (see Row actions). The
aria-describedbyhint on the listbox is supplementary: a description on the listbox container is not reliably announced when focus lands on an option, so whether NVDA and VoiceOver read it on entry is a question for the planned AT check, not a guarantee of this spec. The listbox does not addaria-keyshortcutsto options: support differs across screen readers and it would be repeated on every row. - Opening a context menu from the keyboard on an unselected option in multiple mode replaces a multi-row selection with that one row (see decision 3). Screen readers announce the focused row as selected but not that the other rows were deselected, so the mail example's selection-count live region reads the new count ("1 message selected").
- Manual verification (NVDA + Firefox, VoiceOver + Safari) is planned through the assistive-technology review before the manifest can move to
stable. This spec records no AT evidence.
Mail-list walkthrough
The fixture is an inbox of five messages from Billing, Build bot, Design review, Billing, and Support, in that order, with the reading pane showing the selected message. "Announces" lists what NVDA reads in browse-off focus mode.
Single selection with a reading pane (selectionFollowsFocus, Invoice from Billing selected):
Tabinto the list. Focus lands on the selected first message. Announces "Inbox, list box, Billing: Invoice 4821, selected, 1 of 5".ArrowDown. Focus and selection move to Build bot. Oneupdate:modelValuewith its id; the reading pane follows. Announces "Build bot: Nightly build passed, selected, 2 of 5".End, thenHome. Focus and selection move to Support, then back to Billing.- Type
d. Focus and selection move to Design review. - Press
Shift+F10. The option is selected, so the selection is kept. The menu opens anchored to the option and focuses Archive. Announces the menu and "Archive". Escape. The menu closes and focus returns to Design review.Shift+F10,ArrowDown,Enteron Delete. The consumer removes the message and sets the model to the next message's id. After the DOM update, the removal rule makes the second Billing message active, and the menu's restore asks the listbox to focus it: position 3 of 4. The same Delete is available from the message toolbar above the list.
Multiple selection (multiple, selectionBehavior: 'replace', nothing selected):
- Click the first Billing message. It becomes the only selected message and the anchor.
Shift+clickDesign review. Messages 1 to 3 are selected, in one emit.Ctrl+clickBuild bot. It is deselected: messages 1 and 3 remain.- Right-click Support (not selected). The selection becomes only Support and the menu opens at the pointer.
Escape,Ctrl+A. All five messages are selected. The consumer's live region reads "5 messages selected".ArrowUptwice, thenSpace. Focus moves to Design review without changing the selection, andSpacedeselects it.- Press the
ContextMenukey. Design review is not selected, so the selection of four rows becomes only Design review, and the menu opens on it. The screen reader does not announce the three deselected rows; the consumer's live region reads "1 message selected" (see decision 3).
Rendering and customization
- Headless parts render one element each with the attributes above. No wrapper elements.
class,style, and other attributes pass through. - Styling hooks:
data-part(listbox,option,group,label); on the rootdata-orientation,data-multiple(present in multiple mode), anddata-disabled; on optionsdata-state="checked"when selected,data-disabledwhen disabled, anddata-value. The focused option is styled with:focus-visible(keyboard) or:focus(any). These hooks matchGhostSelectOptionso recipes can share selectors. - Themed recipe (
ghost-listbox): a bordered surface with option rows that match the Select and menu rows: minimum block size, padding, and font read thecontrol.size.smtokens for the active density, as the default theme does for "menu and listbox rows". Rich rows (a mail row with two lines) grow past the minimum. Selected rows use the same selected background asGhostSelectOption, and focus uses the shared focus ring. Only existing--ghost-*tokens; no fixed pixel heights. Nosizeprop in0.4.0. - Scrolling is the consumer's: put a height and
overflow: autoon the root or on aGhostScrollAreaaround it. Keyboard movement keeps the focused option visible in the nearest scroll container.
Environment behavior
SSR and hydration
- Server markup carries roles,
aria-selectedfrom the initial model, and ids fromuseGhostId. - Initial tab stop, following the
GhostTreerule:- The first enabled option in rendered order whose value is in the initial model gets
tabindex="0"; when the model is empty, the first enabled option gets it. - Options render one at a time on the server, so while a model member has not rendered yet, earlier options withhold the stop.
- If no enabled model member renders (a stale, filtered-out, or disabled value), or the list is empty, the server HTML has no
tabindex="0". After mount the first enabled option, or the root of an empty or disabled list, receives it. - A disabled root renders
tabindex="0"on the server, since it does not depend on the options.
- The first enabled option in rendered order whose value is in the initial model gets
- Hydration produces the same attributes with no warnings and no focus change. Listeners attach in
onMounted. - A controlled model that changes between server render and hydration is reconciled after mount without moving DOM focus.
Right-to-left
In horizontal orientation ArrowLeft / ArrowRight follow reading order from dir on the nearest ancestor or the document, as useRovingFocus does: only ltr or rtl on the nearest element with dir counts, and auto or an invalid value there falls through to the document's dir. Vertical keys are unaffected.
Mobile and touch
- Tap selects as in the pointer table. Touch has no modifiers, so multiple selection on touch uses
selectionBehavior: 'toggle', which is the default. Thereplacemail example notes this and offers a "Select" mode toolbar button that switches totoggle. - Long-press opens a context menu through the trigger's existing long-press rule. When the timer fires, the trigger's handshake applies the context-menu selection rule to the option under the original
pointerdown, and the followingclickis ignored. - Touch screen reader users (double-tap and hold) and keyboard users on macOS (no
ContextMenukey) reach every row action through the required visible control outside the list. - Scrolling the list with a finger never selects: a tap is a pointer down and up without movement beyond the trigger's 10 px tolerance.
- Themed options are at least 28 px tall at every density (
control.size.sm.min), above the WCAG 2.2 24 px minimum, and the theme's@media (pointer: coarse)floor raises them to 44 px (control.touch), as for other controls.
Performance
- Target: up to 1,000 mounted options with no perceptible delay on arrow keys and selection, measured in the browser test with a 1,000-option fixture.
- Selection lookups use a
Setof the model built once per model change. Option order is read from the DOM only on navigation, range, and typeahead, not on every render, matchingsortByDocumentOrderuse inGhostSelect. selectionFollowsFocusemits once per key press; consumers with expensive reading panes debounce on their side.- Virtualized selectable lists are not supported in
0.4.0. Longer lists page their data or offer "load more" outside the listbox.
Composition
Reused without public changes:
use-controllable-statefor controlled and uncontrolled selection.typeahead-match(findTypeaheadMatch) for typeahead, already shared by menus and trees.sortByDocumentOrder,useGhostId,isImeComposing, and the development warning registry.
Not used: useRovingFocus / useRovingFocusItems. That helper sets tabindex imperatively after mount, falls back to the first item on any mutation, resyncs a microtask after the Vue flush, and focuses with preventScroll. The listbox instead owns the active option in reactive state and renders tabindex itself, as GhostTree does, which is what the SSR tab stop, the entry rule, removal recovery, and scroll-into-view above require.
Not shared: GhostSelectOption and the useGhostSelect registry are bound to a popup (open state, trigger focus, form mirrors). The build may extract internal helpers used by both (for example multiple-selection array updates and the selection-order rule), but GhostSelect and GhostCombobox public behavior, events, and exports must not change, and their existing tests must pass unchanged. Combobox keeps aria-activedescendant, because its focus stays in the input.
Relationship to useRovingFocus: a consumer can still build a custom composite with useRovingFocus. The listbox docs link to it for "focus-only" lists that need no selection.
Intentional duplication: none beyond the popup listboxes, which keep their own parts.
The one public change outside the new component is the additive focusTarget prop on GhostContextMenuTrigger, defined in the composite trigger amendment.
Test plan
Every Playwright case presses the documented key and asserts real DOM focus (toBeFocused()) and accessible state (aria-selected, aria-disabled, aria-multiselectable), never only tabindex values.
- Framework-neutral unit tests: range computation from anchor to focus in both directions, skipping disabled options;
Ctrl+Aselect and deselect rules with unmounted members kept; selection-order updates for toggle, range, and select-all (appends in rendered order, no duplicates); focus recovery target after removal of one and of several options, including removal combined with insertion and reordering in the same update (the anchored rule in Focus behavior). - Vue component tests:
- Controlled and uncontrolled single and multiple modes;
defaultValuecopied at setup; frozen arrays; controlled rejection; one emit per gesture and none for no-op gestures; clicking the selected option in single mode emits nothing; a controlled single model set from'a'toundefinedclears the selection (no optionaria-selected="true") and stays controlled. - With
['hidden', 'a']andhiddenfiltered out:Shift+clickinreplaceemits only the range in rendered order;Shift+clickintoggle,Ctrl+A, andSpacekeephidden. - Exactly one
tabindex="0"at all times after mount; entry-rule order; an empty or disabled list makes the root the tab stop, and an empty list hands it to the first option that mounts. - Anchor:
Shift+Arrow,Ctrl+A, andCtrl+Shift+Home/Endleave it unchanged;Shift+SpaceafterShift+Arrowranges from the original anchor. activeValueand the optionactive/focusedslot props with focus inside and outside the list.aria-selectedon every option in both modes;aria-multiselectableonly in multiple mode;aria-orientation; disabled root and options.- Consumer
keydown,click, andcontextmenulisteners run first, andpreventDefault()skips listbox handling. focusOptionreturnsfalsefor unmounted and disabled values and never selects.- Development warnings: missing name, duplicate values, group without a label, group inside a
ul/olroot, changingmultiple,selectionFollowsFocuswithmultiple, listbox inside afocusTarget="self"trigger.
- Controlled and uncontrolled single and multiple modes;
- Type tests: the
Multipleinference table and rejected forms from the Select contract, withGhostListbox;focusOptionand exposed types. - SSR:
renderToStringoutput contains the documented roles andaria-selected; exactly onetabindex="0"on the expected element for single, multiple, model-less, and disabled fixtures; none before mount for the empty and stale-model fixtures, and exactly one after hydration. Hydration has no warnings and no focus change. One case in theapps/nuxt-fixtureSSR app. - Playwright keyboard and focus (
tests/e2e/ghost-listbox.spec.ts):- Both mail walkthroughs above, step by step.
- Arrows at both ends with and without
loop;Home/End; horizontal orientation in LTR and RTL; disabled options skipped. - Typeahead: single character, multi-character, repeated character cycling,
Spaceinside a query, buffer reset after 500 ms; IME composition keys ignored. - Multiple mode:
Space,Shift+Arrow,Shift+Space,Ctrl+Shift+Home,Ctrl+Shift+End,Ctrl+Atwice;Metavariants on macOS key mapping. - Pointer table for each mode and
selectionBehavior, includingShift+clicknot selecting page text andShift+clickinreplaceemitting rendered order; on macOS key mapping,Ctrl+clicktakes the context-menu path andCmd+clicktoggles. - Unlisted chords (
Ctrl+Arrow,Shift+Homein multiple mode) are not default-prevented; a loneShiftkeydown keeps the typeahead buffer, and a non-printableAltchord (Alt+ArrowDown) clears it. - A disabled list is reachable with
Taband scrolls with the keyboard. - Scrolled list: keyboard movement keeps the focused option in view.
Escapeinside a dialog closes the dialog.- Removing the focused option (from a key handler and from a context menu action) moves focus by the recovery rule.
- Context menu: right-click on an unselected and on a selected option;
Shift+F10andContextMenukey on an unselected option replace the selection; long-press on an unselected row selects it and opens the menu without a following click toggle; a disabled trigger leaves the selection unchanged; disabled option, group label, padding, empty list, and disabled list do not open the menu; focus returns to the option; after deleting the option, and after a bulk delete of the selection, focus lands on the recovered active option; clicking another row while the menu is open closes the menu, selects that row, and does not return focus to the first row; right-clicking another row while open reopens on that row. - 1,000-option performance fixture.
- Accessibility (axe): single, multiple, grouped, empty, disabled, and context-menu fixtures, including
aria-allowed-attr(noaria-haspopupon the listbox, its options, or the composite trigger wrapper) andnested-interactive. - Context menu regression: existing
GhostContextMenuunit and e2e tests pass unchanged with the defaultfocusTarget; new cases coverfocusTarget="descendant"per the amendment. - Visual:
listbox/basic,listbox/multiple, andlistbox/themedbaselines, light and dark.
Manual assistive-technology checks are planned, not recorded, and gate only the move to stable.
Documentation plan
docs/components/listbox.md: when to use Listbox versus Select, Combobox, RadioGroup, CheckboxGroup, Tree, and DataGrid; API reference generated from the manifest; keyboard table for each mode.- Executable examples under
examples/listbox/:basic(single),multiple(toggle),mail-list(single with reading pane,selectionFollowsFocus, a message toolbar with Archive and Delete acting on the selection, the same actions in a context menu, removal recovery, thearia-describedbyhint, the full row text as the option name with sender and subject first),mail-list-multiple(replacebehavior, selection count live region, toolbar actions on the selection, the same actions in a context menu),groups, andhorizontal. - Accessibility guidance: naming rich rows, the no-interactive-content rule with the DataGrid alternative, the requirement that every context-menu action also has a visible control outside the list, the description hint as a supplement, and announcing bulk selection counts (including the keyboard context-menu case that collapses a selection).
- Context menu docs: a short section on
focus-target="descendant"linking to the mail example. - Playground coverage of single, multiple, groups, and the context menu.
Compatibility and release impact
- New exports in
@ghostvue/vueand@ghostvue/themes: additive minor Changesets for both. GhostContextMenuTriggergainsfocusTargetwith default'self', which keeps today's behavior exactly: additive, covered by the same Changeset. The context menu spec carries the amendment; its own status is "Approved pending review", so approving this spec also approves that amendment to it.GhostSelectandGhostCombobox: no public change.- The build updates this spec's frontmatter
packagesto add@ghostvue/themesand fillsmanifestsonce the parts are exported, then runspnpm manifests:writeandpnpm specs:check. - New manifests start at
experimental.
Open architectural questions
None blocking. Decisions recorded for review:
- Composable export. No
useGhostListboxin0.4.0. The parts cover the requested tasks, and a composable can be added later without breaking them. selectionBehaviordefaulttoggle. Chosen so touch users can make a multiple selection without modifiers and so a multiple listbox clicks like a multipleGhostSelect. Desktop mail lists opt intoreplace.- Context-menu selection rule applies to keyboard opening too. One rule for pointer and keyboard, so the menu target is always the selection and always includes the row it was opened on. Consequence: in the APG multi-select model focus often rests on an unselected row, so opening the menu from the keyboard there collapses a multi-row selection to that row, and screen readers do not announce the rows that were deselected. The mail examples announce the new count in their live region, and the toolbar route acts on the selection without collapsing it. The alternative, keeping a non-empty selection when the focused row is unselected, would let the menu act on rows that exclude the one it was opened on.
- Single selection cannot be cleared by the user. Matches APG single select and
GhostSelect; consumers clear it in code.
Approval
On 2026-12-01, zprue743 approved this specification for implementation in 0.4.0, directing that every change recommended by an independent model review be applied first. The review raised seven required and seven recommended changes; all were applied, and a follow-up review found no open required finding. The approval is recorded in PR #708 and covers the four decisions under Open architectural questions and the composite trigger amendment. It is a design approval only; it is not merge approval of any implementation or a release inclusion decision. Implementation may start against this contract.