Skip to content

GhostSelect ​

GhostSelect is a listbox combobox for forms, filters, and DataTable controls, supporting single-value (string | undefined) and multiple (string[]) models. The examples on this page import the styled parts from @ghostvue/themes; they need no consumer CSS beyond layout. Teams that bring their own design system can start from Advanced: headless composition.

Billing preferences

Billing form with a placeholder, a disabled option, long labels, field validation, and a disabled select.

Billing preferences

Changes apply from the next invoice for Analytical Engines.

The billing form composes themed GhostSelect from @ghostvue/themes with GhostField for labels, hints, and errors. The plan list shows a price line under each name, but textValue keeps the trigger to the short name and drives typeahead; Enterprise is a disabled option that keyboard focus and clicks skip. Invoice currency starts empty, so the trigger shows its muted placeholder. Saving without a currency marks the field invalid and moves focus to its trigger; choosing one clears the error. A long delivery choice ends with an ellipsis in the trigger and wraps inside the list. The tax region select is disabled. Each list opens in a body portal that picks up the light or dark theme. The form keeps a 32rem maximum width and the cycle and currency row stacks when it gets narrow.

Field integration ​

The billing form above shows the wiring. Spread GhostFieldControl slot props onto GhostSelectTrigger, the single tab stop. The trigger takes the field id and aria-describedby, and combines the field's invalid and required state with the root's own invalid and required props for aria-invalid and aria-required. Set required on the root as well when native form validation should block submit.

Forms and reset ​

Alert routing form

Themed native form: named selects with default values, a required escalation owner checked by native validation, Reset back to the defaults, and the submitted form data.

Alert routing

Decide who hears about checkout-service incidents.

Set name on the root and a visually hidden input submits the selected value with the surrounding <form>, so new FormData(form) reads the same values the server would receive. Save routing lists them under Submitted form data. defaultValue (default-value) is the form-reset seed, read at reset time: change the severity or channel, then press Reset and each trigger returns to its default.

Escalation owner sets required on the root. The form uses novalidate to skip the browser's bubbles but still calls form.checkValidity(). The empty select fails native validation, its trigger gets aria-invalid without extra wiring, and the example shows a field error and moves focus to the trigger. Choosing an owner clears the error.

With the keyboard, Tab to a trigger, press Enter, Space, or ArrowDown to open the list on the selected option, move with ArrowDown / ArrowUp (or type the first letters), and press Enter to choose. Escape closes the list and returns focus to the trigger.

Rendering options conditionally never clears the selection. If the selected option unmounts, the value stays selected, keeps submitting with the form, and GhostSelectValue keeps its last known label; no update:modelValue is emitted.

Multiple selection ​

Add multiple to switch the root from string | undefined to a string[] model while keeping the same parts. Selecting an option appends it, deselecting removes it in place, and pressing Space or Enter (or clicking an option) toggles membership while keeping the listbox open and focus on that option.

Multiple labels

Multiple-value GhostSelect with default comma-separated trigger text and a scoped GhostSelectValue summary slot.

DocumentationPerformanceNeeds triage

By default, GhostSelectValue joins selected option labels in model order with ', ' (override with messages.listSeparator). Use the scoped default slot { values, labels } when you need a summary such as "3 labels selected".

Multiple form and reset

Native form participation in multiple mode with FormData.getAll, required constraint validation, and reset.

Notification channels

Multiple values submit as repeated FormData entries and restore on reset.

In native forms, multiple submits one repeated FormData entry per selected value (new FormData(form).getAll(name)), submits nothing ([]) when empty, and validates required when at least one non-empty value is present. Calling form.reset() restores a copy of defaultValue (or []).

Choosing a multiple-selection control ​

  • GhostSelect with multiple — compact trigger with a popup listbox and no text filter, keeping a string[] model in selection order.
  • GhostCombobox with multiple — searchable popup list where users filter options by typing.
  • GhostCheckboxGroup — inline choices that stay visible on the page without opening a popup.

Themed use ​

Themed

Rows-per-page and sort controls on @ghostvue/themes trigger and list tokens.

Sort by
Rows per page

The themed trigger takes its label's width in a toolbar or table cell, fills a GhostField or grid cell, and fills any container with block; see form control widths. The value takes the free space and ends a long label with an ellipsis; extra children such as an icon keep their size. Like a native <select>, a long label still counts toward the trigger's minimum width, so give a grid track or flex item that holds it a zero minimum (minmax(0, 1fr) or min-inline-size: 0) when the label should truncate. A placeholder is muted. Keyboard focus and the open state share the focus ring, an aria-invalid trigger gets the danger border, and a disabled trigger uses the disabled action tokens. Hover changes only colors, so the control never shifts. In the list, long option labels wrap, hovered options get a muted fill, and the selected option is muted and medium weight.

Size ​

Size

Small select trigger in a filter bar beside a small input and button.

Set size to sm, md (the default) or lg on the themed GhostSelectTrigger to match a GhostButton or GhostInput of the same size. The trigger takes its height, minimum width, label size and padding from control.size.<size>. The open list keeps the same option size at every trigger size. On touch screens every size keeps a 44px trigger. When as is a component, the wrapper keeps size for itself and does not pass it on.

Advanced: headless composition ​

This section is for teams that bring their own design system and style the parts themselves. Import the same parts from @ghostvue/vue; behavior, ARIA, and form participation are identical, but nothing is painted.

Headless select ​

Basic Headless

Single-value combobox with listbox options, typeahead, and portaled content.

The trigger is a role="combobox" control; options live in a portaled listbox. The headless layer paints nothing, so the example styles its own trigger chevron, list surface, check mark, and highlighted, selected and disabled option states from aria-selected, aria-disabled and focus.

Headless form ​

Form Headless

Hidden input submit value and native form reset.

The same name and default-value contract without a theme. The list renders inline (:portal="false") and the sample brings its own consumer CSS. The headless field wiring is the select/field example on the GhostSelect reference page.

API ​

GhostSelect ​

PropTypeDefaultDescription
defaultOpenbooleanfalseInitial open state.
defaultValueGhostSelectValueInput<Multiple>—Uncontrolled seed and reset value.
disabledbooleanfalseDisables the control.
formstring—Declared prop form.
invalidbooleanfalsearia-invalid on the trigger.
messagesGhostSelectMessages—Overridable internal strings (required validation message, default 'Select a value.'; listSeparator, default ', ').
modelValueGhostSelectValueInput<Multiple>—Controlled value.
multipleMultiple—Enables multiple-value selection in string[]. Read once at setup.
namestring—Submit input name.
openboolean—Controlled listbox open state.
placeholderstring—Shown when no value is selected.
requiredbooleanfalseRequired when name is set.
SlotSlot propsDescription
default—Primary content.

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

GhostSelectTrigger ​

The themed trigger adds block and size. sm and lg render data-size on the trigger; the default md renders none.

@ghostvue/themes adds these to the headless GhostSelectTrigger API, which it forwards:

PropTypeDefaultDescription
blockboolean"false"Fill the container's inline size via data-block. Without it the trigger takes its content width, except in a flex column such as GhostField, which stretches it.
size'sm' | 'md' | 'lg'"md"Trigger height, minimum width, label size, and padding from control.size.<size>, matching a GhostButton or GhostInput of the same size. The open listbox does not change. The wrapper consumes size and does not forward it to a component as host. The default omits data-size so CSS can treat a missing hook as md.

Parts ​

  • GhostSelectTrigger, GhostSelectValue, GhostSelectContent
  • GhostSelectOption, GhostSelectGroup, GhostSelectLabel
  • useGhostSelect for advanced composition. Pass { multiple: true } for an array model, including when specifying useGhostSelect<true> explicitly.

See the specification for keyboard, typeahead, portal, and SSR behavior. Keys owned by an active IME composition do not run typeahead or listbox commands.