GhostSelect reference
Package: @ghostvue/themes. Status: experimental (stability policy).
Themed GhostSelect trigger and listbox surfaces using semantic --ghost-* tokens.
Generated from the component manifest. Edit the manifest or Vue source, then rebuild the docs.
Props
None declared.
Emits
None declared.
Models
None declared.
Slots
None declared.
Exposed members
None declared.
Parts and data attributes
| Attribute | Value | Description |
|---|---|---|
data-part | trigger | ghost-select-trigger surface aligned to control tokens. Takes its content width, fills a GhostField, and fills any container with the trigger's block prop (data-block). |
data-part | value | Selected label or placeholder; fills the trigger and ends long labels with an ellipsis. |
data-part | content | Elevated listbox panel, capped to the viewport width. |
data-part | option | Listbox row; long labels wrap. |
data-state | placeholder | Muted value text while nothing is selected. |
data-state | invalid | Danger border when the trigger has aria-invalid, from the root or a GhostField. |
data-state | disabled | Disabled action tokens on the trigger; disabled options are muted. |
data-state | open | Focus ring on the trigger while the listbox is open; also shown on keyboard focus. |
data-state | checked | Muted fill and medium weight on the selected option. |
CSS variables
None declared.
Accessibility
Role: combobox. APG pattern: https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/.
Required ARIA attributes: none.
Keyboard
None declared.
Verification
Each category is reviewed separately. Automated keyboard and axe results do not attest manual or assistive-technology review.
| Category | Status | Evidence |
|---|---|---|
| Automated keyboard | Not reviewed | No declared key is mapped to a browser test yet. |
| Manual interaction | Not reviewed | No review recorded. |
| Assistive technology | Not reviewed | No review recorded. |
Examples
select/billing-preferences
Billing form with a placeholder, a disabled option, long labels, field validation, and a disabled select.
<script setup lang="ts">
import { computed, nextTick, ref } from 'vue'
import {
GhostButton,
GhostCard,
GhostField,
GhostFieldControl,
GhostFieldDescription,
GhostFieldError,
GhostFieldLabel,
GhostSelect,
GhostSelectContent,
GhostSelectOption,
GhostSelectTrigger,
GhostSelectValue,
} from '@ghostvue/themes'
/*
* Deterministic local data. Plans carry a short name for the trigger
* (`textValue`) and a price line that only shows in the list.
*/
const plans = [
{ value: 'starter', name: 'Starter', price: 'Free for up to 3 seats' },
{ value: 'team', name: 'Team', price: '$12 per seat / month' },
{ value: 'business', name: 'Business', price: '$24 per seat / month' },
// Enterprise needs a sales contract, so it is listed but not selectable.
{
value: 'enterprise',
name: 'Enterprise',
price: 'Contact sales',
disabled: true,
},
] as const
const cycles = [
{ value: 'monthly', label: 'Monthly' },
{ value: 'annual', label: 'Annual (2 months free)' },
] as const
const currencies = [
{ value: 'usd', label: 'US dollar (USD)' },
{ value: 'eur', label: 'Euro (EUR)' },
{ value: 'gbp', label: 'British pound (GBP)' },
{ value: 'jpy', label: 'Japanese yen (JPY)' },
] as const
const deliveries = [
{ value: 'owner', label: 'Email the PDF invoice to the workspace owner' },
{
value: 'finance',
label:
'Email the PDF invoice to finance@analytical-engines.example and copy every workspace admin',
},
{ value: 'portal', label: 'Publish to the billing portal only' },
] as const
const plan = ref<string | undefined>('team')
const cycle = ref<string | undefined>('annual')
// No currency yet: the trigger shows its placeholder on first render.
const currency = ref<string | undefined>(undefined)
const delivery = ref<string | undefined>('finance')
const taxRegion = 'gb'
const submitted = ref(false)
const saved = ref(false)
const currencyInvalid = computed(
() => submitted.value && currency.value === undefined,
)
const summary = computed(() => {
const planName = plans.find((option) => option.value === plan.value)?.name
const billed = cycle.value === 'annual' ? 'annually' : 'monthly'
const code = currency.value?.toUpperCase()
return `${planName ?? 'No'} plan, billed ${billed}${code ? ` in ${code}` : ''}.`
})
async function save(event: SubmitEvent): Promise<void> {
// Read before awaiting: currentTarget is cleared once dispatch ends.
const form = event.currentTarget
submitted.value = true
saved.value = !currencyInvalid.value
if (saved.value || !(form instanceof HTMLFormElement)) return
// Wait for aria-invalid to render, then focus the first control to fix.
await nextTick()
form.querySelector<HTMLElement>('[aria-invalid="true"]')?.focus()
}
function markEdited(): void {
saved.value = false
}
</script>
<template>
<form class="billing" novalidate @submit.prevent="save">
<GhostCard as="section" aria-labelledby="billing-title">
<template #header>
<div class="billing__header">
<h2 id="billing-title" class="billing__title">Billing preferences</h2>
<p class="billing__lead">
Changes apply from the next invoice for Analytical Engines.
</p>
</div>
</template>
<div class="billing__fields">
<GhostField>
<GhostFieldLabel>Plan</GhostFieldLabel>
<GhostFieldDescription>
Enterprise needs a signed contract.
</GhostFieldDescription>
<GhostFieldControl v-slot="field">
<GhostSelect
v-model="plan"
name="plan"
placeholder="Choose a plan"
@update:model-value="markEdited"
>
<GhostSelectTrigger v-bind="field">
<GhostSelectValue />
<svg
class="billing__chevron"
viewBox="0 0 16 16"
aria-hidden="true"
>
<path d="m4 6 4 4 4-4" />
</svg>
</GhostSelectTrigger>
<GhostSelectContent :offset="6">
<GhostSelectOption
v-for="option in plans"
:key="option.value"
:value="option.value"
:text-value="option.name"
:disabled="'disabled' in option && option.disabled"
>
<span class="billing__option">
<span class="billing__option-name">{{ option.name }}</span>
<span class="billing__option-meta">{{ option.price }}</span>
</span>
</GhostSelectOption>
</GhostSelectContent>
</GhostSelect>
</GhostFieldControl>
</GhostField>
<div class="billing__row">
<GhostField>
<GhostFieldLabel>Billing cycle</GhostFieldLabel>
<GhostFieldControl v-slot="field">
<GhostSelect
v-model="cycle"
name="cycle"
placeholder="Choose a cycle"
@update:model-value="markEdited"
>
<GhostSelectTrigger v-bind="field">
<GhostSelectValue />
<svg
class="billing__chevron"
viewBox="0 0 16 16"
aria-hidden="true"
>
<path d="m4 6 4 4 4-4" />
</svg>
</GhostSelectTrigger>
<GhostSelectContent :offset="6">
<GhostSelectOption
v-for="option in cycles"
:key="option.value"
:value="option.value"
>
<span class="billing__option">{{ option.label }}</span>
</GhostSelectOption>
</GhostSelectContent>
</GhostSelect>
</GhostFieldControl>
</GhostField>
<GhostField required :invalid="currencyInvalid">
<GhostFieldLabel required>Invoice currency</GhostFieldLabel>
<GhostFieldControl v-slot="field">
<GhostSelect
v-model="currency"
name="currency"
placeholder="Choose a currency"
@update:model-value="markEdited"
>
<GhostSelectTrigger v-bind="field">
<GhostSelectValue />
<svg
class="billing__chevron"
viewBox="0 0 16 16"
aria-hidden="true"
>
<path d="m4 6 4 4 4-4" />
</svg>
</GhostSelectTrigger>
<GhostSelectContent :offset="6">
<GhostSelectOption
v-for="option in currencies"
:key="option.value"
:value="option.value"
>
<span class="billing__option">{{ option.label }}</span>
</GhostSelectOption>
</GhostSelectContent>
</GhostSelect>
</GhostFieldControl>
<GhostFieldError v-if="currencyInvalid">
Choose an invoice currency.
</GhostFieldError>
</GhostField>
</div>
<GhostField>
<GhostFieldLabel>Invoice delivery</GhostFieldLabel>
<GhostFieldDescription>
Long choices end with an ellipsis here and wrap in the list.
</GhostFieldDescription>
<GhostFieldControl v-slot="field">
<GhostSelect
v-model="delivery"
name="delivery"
placeholder="Choose a delivery method"
@update:model-value="markEdited"
>
<GhostSelectTrigger v-bind="field">
<GhostSelectValue />
<svg
class="billing__chevron"
viewBox="0 0 16 16"
aria-hidden="true"
>
<path d="m4 6 4 4 4-4" />
</svg>
</GhostSelectTrigger>
<GhostSelectContent :offset="6">
<GhostSelectOption
v-for="option in deliveries"
:key="option.value"
:value="option.value"
>
<span class="billing__option">{{ option.label }}</span>
</GhostSelectOption>
</GhostSelectContent>
</GhostSelect>
</GhostFieldControl>
</GhostField>
<GhostField disabled>
<GhostFieldLabel>Tax region</GhostFieldLabel>
<GhostFieldDescription>
Managed by your organization's finance team.
</GhostFieldDescription>
<GhostFieldControl v-slot="field">
<GhostSelect :model-value="taxRegion" name="tax-region" disabled>
<GhostSelectTrigger v-bind="field">
<GhostSelectValue />
<svg
class="billing__chevron"
viewBox="0 0 16 16"
aria-hidden="true"
>
<path d="m4 6 4 4 4-4" />
</svg>
</GhostSelectTrigger>
<GhostSelectContent :offset="6">
<GhostSelectOption value="gb">
United Kingdom (VAT registered)
</GhostSelectOption>
</GhostSelectContent>
</GhostSelect>
</GhostFieldControl>
</GhostField>
</div>
<template #footer>
<div class="billing__actions">
<p class="billing__status" role="status">
{{ saved ? `Preferences saved. ${summary}` : '' }}
</p>
<GhostButton type="submit">Save preferences</GhostButton>
</div>
</template>
</GhostCard>
</form>
</template>
<style scoped>
/*
* The form owns its width: 32rem keeps labels, hints, and triggers at a
* readable measure and lets the card shrink with the preview on phones.
*/
.billing {
max-inline-size: 32rem;
}
.billing__header {
display: grid;
gap: var(--ghost-space-gap-xs);
padding-block-end: var(--ghost-space-stack-sm);
}
/* Native text picks up docs prose styles, so each element resets its own. */
.billing__title {
color: var(--ghost-text-default);
font-size: var(--ghost-type-size-lg);
font-weight: var(--ghost-type-weight-semibold);
line-height: var(--ghost-type-line-tight);
margin: 0;
}
.billing__lead,
.billing__status {
color: var(--ghost-text-muted);
font-size: var(--ghost-type-size-sm);
line-height: var(--ghost-type-line-snug);
margin: 0;
}
/*
* A zero track minimum lets a long selected label truncate. Without it the
* label's one-line width becomes the column's minimum and widens the card.
*/
.billing__fields {
display: grid;
gap: var(--ghost-space-stack-lg);
grid-template-columns: minmax(0, 1fr);
}
/* Cycle and currency share a row when each keeps about 11rem; else stack. */
.billing__row {
display: grid;
gap: var(--ghost-space-stack-lg) var(--ghost-space-gap-md);
grid-template-columns: repeat(auto-fit, minmax(min(11rem, 100%), 1fr));
}
.billing :deep([data-part='description']),
.billing :deep([data-part='error']) {
overflow-wrap: anywhere;
}
/* Decorative; inherits the trigger color, including the disabled tone. */
.billing__chevron {
block-size: 1em;
fill: none;
inline-size: 1em;
stroke: currentcolor;
stroke-linecap: round;
stroke-linejoin: round;
stroke-width: 1.5;
}
/*
* Option text is authored here, so these scoped rules reach it inside the
* body portal. 22rem keeps long delivery choices wrapping at a readable
* measure instead of stretching the list to the viewport.
*/
.billing__option {
display: grid;
font-size: var(--ghost-type-size-sm);
gap: var(--ghost-space-gap-xs);
line-height: var(--ghost-type-line-snug);
max-inline-size: 22rem;
}
.billing__option-meta {
color: var(--ghost-text-muted);
font-size: var(--ghost-type-size-xs);
font-weight: var(--ghost-type-weight-regular);
}
.billing__actions {
align-items: center;
display: flex;
flex-wrap: wrap;
gap: var(--ghost-space-gap-sm) var(--ghost-space-gap-md);
justify-content: flex-end;
}
.billing__status {
flex: 1 1 auto;
}
</style>
select/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.
<script setup lang="ts">
import { nextTick, ref } from 'vue'
import {
GhostButton,
GhostCard,
GhostField,
GhostFieldControl,
GhostFieldDescription,
GhostFieldError,
GhostFieldLabel,
GhostSelect,
GhostSelectContent,
GhostSelectOption,
GhostSelectTrigger,
GhostSelectValue,
} from '@ghostvue/themes'
// Deterministic local data: option values are what the form submits.
const severities = [
{ value: 'critical', label: 'Critical only' },
{ value: 'high', label: 'High and above' },
{ value: 'all', label: 'Every alert' },
] as const
const channels = [
{ value: 'pager', label: 'Page the on-call phone' },
{ value: 'slack', label: 'Post to #incidents' },
{ value: 'email', label: 'Email the team list' },
] as const
const owners = [
{ value: 'platform', label: 'Platform on-call' },
{ value: 'payments', label: 'Payments on-call' },
{ value: 'support', label: 'Support leads' },
] as const
const labels: Record<string, string> = Object.fromEntries(
[...severities, ...channels, ...owners].map((option) => [
option.value,
option.label,
]),
)
interface SubmittedEntry {
name: string
value: string
}
const ownerMissing = ref(false)
const submitted = ref<SubmittedEntry[]>([])
const status = ref('')
/*
* `novalidate` turns off the browser's bubbles, but `checkValidity()` still
* runs native constraint validation. The required Select's hidden input
* fails it, fires `invalid`, and the trigger gets `aria-invalid` on its own;
* the field error and focus move are this form's choices.
*/
async function save(event: SubmitEvent): Promise<void> {
// Read before awaiting: currentTarget is cleared once dispatch ends.
const form = event.currentTarget
if (!(form instanceof HTMLFormElement)) return
if (!form.checkValidity()) {
ownerMissing.value = true
submitted.value = []
status.value = ''
// Wait for aria-invalid to render, then focus the control to fix.
await nextTick()
form.querySelector<HTMLElement>('[aria-invalid="true"]')?.focus()
return
}
// Exactly what a native submit would send: one entry per named Select.
submitted.value = [...new FormData(form)].map(([name, value]) => ({
name,
value: typeof value === 'string' ? value : value.name,
}))
status.value = 'Alert routing saved.'
}
// Native reset restores each Select's `default-value`; clear our own state.
function onReset(): void {
ownerMissing.value = false
submitted.value = []
status.value = 'Form reset to the saved defaults.'
}
function onOwnerChange(): void {
ownerMissing.value = false
}
</script>
<template>
<form class="routing" novalidate @submit.prevent="save" @reset="onReset">
<GhostCard as="section" aria-labelledby="routing-title">
<template #header>
<div class="routing__header">
<h2 id="routing-title" class="routing__title">Alert routing</h2>
<p class="routing__lead">
Decide who hears about checkout-service incidents.
</p>
</div>
</template>
<div class="routing__fields">
<GhostField>
<GhostFieldLabel>Minimum severity</GhostFieldLabel>
<GhostFieldControl v-slot="field">
<GhostSelect name="severity" default-value="high">
<GhostSelectTrigger v-bind="field">
<GhostSelectValue />
<svg
class="routing__chevron"
viewBox="0 0 16 16"
aria-hidden="true"
>
<path d="m4 6 4 4 4-4" />
</svg>
</GhostSelectTrigger>
<GhostSelectContent :offset="6">
<GhostSelectOption
v-for="option in severities"
:key="option.value"
:value="option.value"
>
{{ option.label }}
</GhostSelectOption>
</GhostSelectContent>
</GhostSelect>
</GhostFieldControl>
</GhostField>
<GhostField>
<GhostFieldLabel>Notify by</GhostFieldLabel>
<GhostFieldControl v-slot="field">
<GhostSelect name="channel" default-value="slack">
<GhostSelectTrigger v-bind="field">
<GhostSelectValue />
<svg
class="routing__chevron"
viewBox="0 0 16 16"
aria-hidden="true"
>
<path d="m4 6 4 4 4-4" />
</svg>
</GhostSelectTrigger>
<GhostSelectContent :offset="6">
<GhostSelectOption
v-for="option in channels"
:key="option.value"
:value="option.value"
>
{{ option.label }}
</GhostSelectOption>
</GhostSelectContent>
</GhostSelect>
</GhostFieldControl>
</GhostField>
<GhostField required :invalid="ownerMissing">
<GhostFieldLabel required>Escalation owner</GhostFieldLabel>
<GhostFieldDescription>
Paged when an alert is not acknowledged in 15 minutes.
</GhostFieldDescription>
<GhostFieldControl v-slot="field">
<!-- `required` on the root enables native form validation. -->
<GhostSelect
name="escalation"
required
placeholder="Choose an owner"
@update:model-value="onOwnerChange"
>
<GhostSelectTrigger v-bind="field">
<GhostSelectValue />
<svg
class="routing__chevron"
viewBox="0 0 16 16"
aria-hidden="true"
>
<path d="m4 6 4 4 4-4" />
</svg>
</GhostSelectTrigger>
<GhostSelectContent :offset="6">
<GhostSelectOption
v-for="option in owners"
:key="option.value"
:value="option.value"
>
{{ option.label }}
</GhostSelectOption>
</GhostSelectContent>
</GhostSelect>
</GhostFieldControl>
<GhostFieldError v-if="ownerMissing">
Choose who gets escalations.
</GhostFieldError>
</GhostField>
</div>
<template #footer>
<div class="routing__footer">
<p class="routing__status" role="status">{{ status }}</p>
<div class="routing__actions">
<GhostButton type="reset" variant="ghost" tone="neutral">
Reset
</GhostButton>
<GhostButton type="submit">Save routing</GhostButton>
</div>
</div>
<section
v-if="submitted.length > 0"
class="routing__submitted"
aria-labelledby="routing-submitted-title"
>
<h3 id="routing-submitted-title" class="routing__submitted-title">
Submitted form data
</h3>
<dl class="routing__entries">
<div
v-for="entry in submitted"
:key="entry.name"
class="routing__entry"
>
<dt>
<code>{{ entry.name }}</code>
</dt>
<dd>
<code>{{ entry.value }}</code>
<span class="routing__entry-label">
{{ labels[entry.value] }}
</span>
</dd>
</div>
</dl>
</section>
</template>
</GhostCard>
</form>
</template>
<style scoped>
/* The form keeps a readable measure and shrinks with the preview on phones. */
.routing {
max-inline-size: 32rem;
}
.routing__header {
display: grid;
gap: var(--ghost-space-gap-xs);
padding-block-end: var(--ghost-space-stack-sm);
}
/* Native text picks up docs prose styles, so each element resets its own. */
.routing__title,
.routing__submitted-title {
border: 0;
color: var(--ghost-text-default);
font-size: var(--ghost-type-size-lg);
font-weight: var(--ghost-type-weight-semibold);
line-height: var(--ghost-type-line-tight);
margin: 0;
padding: 0;
}
.routing__submitted-title {
font-size: var(--ghost-type-size-sm);
}
.routing__lead,
.routing__status {
color: var(--ghost-text-muted);
font-size: var(--ghost-type-size-sm);
line-height: var(--ghost-type-line-snug);
margin: 0;
}
/* A zero track minimum lets a long selected label truncate in its trigger. */
.routing__fields {
display: grid;
gap: var(--ghost-space-stack-lg);
grid-template-columns: minmax(0, 1fr);
}
/* Decorative; inherits the trigger color, including the invalid state. */
.routing__chevron {
block-size: 1em;
fill: none;
inline-size: 1em;
stroke: currentcolor;
stroke-linecap: round;
stroke-linejoin: round;
stroke-width: 1.5;
}
.routing__footer {
align-items: center;
display: flex;
flex-wrap: wrap;
gap: var(--ghost-space-gap-sm) var(--ghost-space-gap-md);
justify-content: flex-end;
}
.routing__status {
flex: 1 1 10rem;
}
.routing__actions {
display: flex;
gap: var(--ghost-space-gap-sm);
}
.routing__submitted {
border-block-start: var(--ghost-border-hairline-width) solid
var(--ghost-border-default);
display: grid;
gap: var(--ghost-space-gap-sm);
margin-block-start: var(--ghost-space-stack-md);
padding-block-start: var(--ghost-space-stack-md);
}
.routing__entries {
display: grid;
gap: var(--ghost-space-gap-xs);
margin: 0;
}
.routing__entry {
column-gap: var(--ghost-space-gap-md);
display: grid;
font-size: var(--ghost-type-size-sm);
grid-template-columns: minmax(0, 7rem) minmax(0, 1fr);
line-height: var(--ghost-type-line-snug);
}
.routing__entry dt,
.routing__entry dd {
margin: 0;
min-inline-size: 0;
overflow-wrap: anywhere;
}
.routing__entry code {
background: none;
color: var(--ghost-text-default);
/* Reset docs inline-code styles; the token set has no mono family. */
border-radius: 0;
font: inherit;
font-weight: var(--ghost-type-weight-medium);
padding: 0;
}
.routing__entry-label {
color: var(--ghost-text-muted);
margin-inline-start: var(--ghost-space-gap-sm);
}
</style>
select/multiple-labels
Multiple-value GhostSelect with default comma-separated trigger text and a scoped GhostSelectValue summary slot.
Space or Enter toggles an option and keeps the list open.
Scoped slot props expose selected values and labels in selection order.
<script setup lang="ts">
import { ref } from 'vue'
import {
GhostBadge,
GhostField,
GhostFieldControl,
GhostFieldDescription,
GhostFieldLabel,
GhostSelect,
GhostSelectContent,
GhostSelectOption,
GhostSelectTrigger,
GhostSelectValue,
} from '@ghostvue/themes'
const labelOptions = [
{ value: 'bug', label: 'Bug' },
{ value: 'docs', label: 'Documentation' },
{ value: 'a11y', label: 'Accessibility' },
{ value: 'perf', label: 'Performance' },
{ value: 'triage', label: 'Needs triage' },
] as const
const labelNames = Object.fromEntries(
labelOptions.map((option) => [option.value, option.label]),
) as Record<string, string>
const issueLabels = ref<string[]>(['bug', 'a11y'])
const summaryLabels = ref<string[]>(['docs', 'perf', 'triage'])
</script>
<template>
<div class="multi-labels">
<GhostField>
<GhostFieldLabel>Issue labels</GhostFieldLabel>
<GhostFieldDescription>
Space or Enter toggles an option and keeps the list open.
</GhostFieldDescription>
<GhostFieldControl v-slot="field">
<GhostSelect v-model="issueLabels" multiple placeholder="Add labels">
<GhostSelectTrigger v-bind="field">
<GhostSelectValue />
<svg
class="multi-labels__chevron"
viewBox="0 0 16 16"
aria-hidden="true"
>
<path d="m4 6 4 4 4-4" />
</svg>
</GhostSelectTrigger>
<GhostSelectContent :offset="6">
<GhostSelectOption
v-for="option in labelOptions"
:key="option.value"
:value="option.value"
>
{{ option.label }}
</GhostSelectOption>
</GhostSelectContent>
</GhostSelect>
</GhostFieldControl>
</GhostField>
<GhostField>
<GhostFieldLabel>Custom summary slot</GhostFieldLabel>
<GhostFieldDescription>
Scoped slot props expose selected values and labels in selection order.
</GhostFieldDescription>
<GhostFieldControl v-slot="field">
<GhostSelect
v-model="summaryLabels"
multiple
placeholder="Pick categories"
>
<GhostSelectTrigger v-bind="field">
<GhostSelectValue>
<template #default="{ values, labels }">
{{
values.length === 1
? labels[0]
: `${String(values.length)} labels selected`
}}
</template>
</GhostSelectValue>
<svg
class="multi-labels__chevron"
viewBox="0 0 16 16"
aria-hidden="true"
>
<path d="m4 6 4 4 4-4" />
</svg>
</GhostSelectTrigger>
<GhostSelectContent :offset="6">
<GhostSelectOption
v-for="option in labelOptions"
:key="option.value"
:value="option.value"
>
{{ option.label }}
</GhostSelectOption>
</GhostSelectContent>
</GhostSelect>
</GhostFieldControl>
</GhostField>
<div
v-if="summaryLabels.length > 0"
class="multi-labels__selected"
aria-label="Selected categories"
>
<GhostBadge v-for="value in summaryLabels" :key="value" tone="neutral">
{{ labelNames[value] ?? value }}
</GhostBadge>
</div>
</div>
</template>
<style scoped>
.multi-labels {
display: grid;
gap: var(--ghost-space-stack-lg);
grid-template-columns: minmax(0, 1fr);
max-inline-size: 28rem;
}
.multi-labels__chevron {
block-size: 1em;
fill: none;
inline-size: 1em;
stroke: currentcolor;
stroke-linecap: round;
stroke-linejoin: round;
stroke-width: 1.5;
}
.multi-labels__selected {
display: flex;
flex-wrap: wrap;
gap: var(--ghost-space-gap-xs);
}
</style>
select/multiple-form
Native form participation in multiple mode with FormData.getAll, required constraint validation, and reset.
<script setup lang="ts">
import { nextTick, ref } from 'vue'
import {
GhostButton,
GhostCard,
GhostField,
GhostFieldControl,
GhostFieldDescription,
GhostFieldError,
GhostFieldLabel,
GhostSelect,
GhostSelectContent,
GhostSelectOption,
GhostSelectTrigger,
GhostSelectValue,
} from '@ghostvue/themes'
const channels = [
{ value: 'email', label: 'Email digest' },
{ value: 'slack', label: 'Slack channel' },
{ value: 'pager', label: 'Pager alert' },
{ value: 'webhook', label: 'Audit webhook' },
] as const
const defaultChannels = ['email', 'slack'] as const
const channelsMissing = ref(false)
const submittedChannels = ref<string[] | null>(null)
const status = ref('')
async function save(event: SubmitEvent): Promise<void> {
const form = event.currentTarget
if (!(form instanceof HTMLFormElement)) return
if (!form.checkValidity()) {
channelsMissing.value = true
submittedChannels.value = null
status.value = ''
await nextTick()
form.querySelector<HTMLElement>('[aria-invalid="true"]')?.focus()
return
}
channelsMissing.value = false
submittedChannels.value = new FormData(form)
.getAll('channels')
.map((entry) => (typeof entry === 'string' ? entry : entry.name))
status.value = 'Notification rules saved.'
}
function onReset(): void {
channelsMissing.value = false
submittedChannels.value = null
status.value = 'Restored default channels.'
}
function onChannelsChange(next: string[]): void {
if (next.length > 0) {
channelsMissing.value = false
}
}
</script>
<template>
<form class="multi-form" novalidate @submit.prevent="save" @reset="onReset">
<GhostCard as="section" aria-labelledby="multi-form-title">
<template #header>
<div class="multi-form__header">
<h2 id="multi-form-title" class="multi-form__title">
Notification channels
</h2>
<p class="multi-form__lead">
Multiple values submit as repeated FormData entries and restore on
reset.
</p>
</div>
</template>
<GhostField required :invalid="channelsMissing">
<GhostFieldLabel required>Delivery channels</GhostFieldLabel>
<GhostFieldDescription>
Choose at least one channel before saving.
</GhostFieldDescription>
<GhostFieldControl v-slot="field">
<GhostSelect
multiple
name="channels"
required
:default-value="defaultChannels"
placeholder="Choose channels"
@update:model-value="onChannelsChange"
>
<GhostSelectTrigger v-bind="field">
<GhostSelectValue />
<svg
class="multi-form__chevron"
viewBox="0 0 16 16"
aria-hidden="true"
>
<path d="m4 6 4 4 4-4" />
</svg>
</GhostSelectTrigger>
<GhostSelectContent :offset="6">
<GhostSelectOption
v-for="option in channels"
:key="option.value"
:value="option.value"
>
{{ option.label }}
</GhostSelectOption>
</GhostSelectContent>
</GhostSelect>
</GhostFieldControl>
<GhostFieldError v-if="channelsMissing">
Select at least one delivery channel.
</GhostFieldError>
</GhostField>
<template #footer>
<div class="multi-form__footer">
<p class="multi-form__status" role="status">{{ status }}</p>
<div class="multi-form__actions">
<GhostButton type="reset" variant="ghost" tone="neutral">
Reset
</GhostButton>
<GhostButton type="submit">Save channels</GhostButton>
</div>
</div>
<p v-if="submittedChannels !== null" class="multi-form__output">
<code>FormData.getAll('channels')</code>:
<code>{{ JSON.stringify(submittedChannels) }}</code>
</p>
</template>
</GhostCard>
</form>
</template>
<style scoped>
.multi-form {
max-inline-size: 30rem;
}
.multi-form__header {
display: grid;
gap: var(--ghost-space-gap-xs);
padding-block-end: var(--ghost-space-stack-sm);
}
.multi-form__title {
border: 0;
color: var(--ghost-text-default);
font-size: var(--ghost-type-size-lg);
font-weight: var(--ghost-type-weight-semibold);
line-height: var(--ghost-type-line-tight);
margin: 0;
padding: 0;
}
.multi-form__lead,
.multi-form__status,
.multi-form__output {
color: var(--ghost-text-muted);
font-size: var(--ghost-type-size-sm);
line-height: var(--ghost-type-line-snug);
margin: 0;
}
.multi-form__chevron {
block-size: 1em;
fill: none;
inline-size: 1em;
stroke: currentcolor;
stroke-linecap: round;
stroke-linejoin: round;
stroke-width: 1.5;
}
.multi-form__footer {
align-items: center;
display: flex;
flex-wrap: wrap;
gap: var(--ghost-space-gap-sm) var(--ghost-space-gap-md);
justify-content: flex-end;
}
.multi-form__status {
flex: 1 1 10rem;
}
.multi-form__actions {
display: flex;
gap: var(--ghost-space-gap-sm);
}
.multi-form__output {
border-block-start: var(--ghost-border-hairline-width) solid
var(--ghost-border-default);
color: var(--ghost-text-default);
margin-block-start: var(--ghost-space-stack-md);
padding-block-start: var(--ghost-space-stack-md);
}
</style>
select/themed
Rows-per-page and sort controls on @ghostvue/themes trigger and list tokens.
<script setup lang="ts">
import { ref } from 'vue'
import {
GhostSelect,
GhostSelectContent,
GhostSelectOption,
GhostSelectTrigger,
GhostSelectValue,
} from '@ghostvue/themes'
const pageSize = ref<string | undefined>('25')
const sort = ref<string | undefined>('updated')
</script>
<template>
<div class="toolbar">
<div class="toolbar__control">
<span id="toolbar-sort-label" class="toolbar__label">Sort by</span>
<GhostSelect v-model="sort" placeholder="Sort by">
<GhostSelectTrigger aria-labelledby="toolbar-sort-label">
<GhostSelectValue />
</GhostSelectTrigger>
<GhostSelectContent :offset="6">
<GhostSelectOption value="updated">Last updated</GhostSelectOption>
<GhostSelectOption value="name">Name</GhostSelectOption>
<GhostSelectOption value="owner">Owner</GhostSelectOption>
</GhostSelectContent>
</GhostSelect>
</div>
<div class="toolbar__control toolbar__control--narrow">
<span id="toolbar-rows-label" class="toolbar__label">Rows per page</span>
<GhostSelect v-model="pageSize" placeholder="Rows per page">
<GhostSelectTrigger aria-labelledby="toolbar-rows-label">
<GhostSelectValue />
</GhostSelectTrigger>
<GhostSelectContent :offset="6">
<GhostSelectOption value="10">10 rows</GhostSelectOption>
<GhostSelectOption value="25">25 rows</GhostSelectOption>
<GhostSelectOption value="50">50 rows</GhostSelectOption>
</GhostSelectContent>
</GhostSelect>
</div>
</div>
</template>
<style scoped>
/* A table toolbar: controls sit side by side and wrap on narrow previews. */
.toolbar {
align-items: end;
display: flex;
flex-wrap: wrap;
gap: var(--ghost-space-stack-md) var(--ghost-space-gap-md);
}
.toolbar__control {
display: grid;
flex: 0 1 12rem;
gap: var(--ghost-space-gap-xs);
min-inline-size: 0;
}
.toolbar__control--narrow {
flex-basis: 9rem;
}
.toolbar__label {
color: var(--ghost-text-muted);
font-size: var(--ghost-type-size-sm);
font-weight: var(--ghost-type-weight-medium);
line-height: var(--ghost-type-line-snug);
}
</style>
select/size
Small select trigger in a filter bar beside a small input and button.
<script setup lang="ts">
import { ref } from 'vue'
import {
GhostButton,
GhostInput,
GhostSelect,
GhostSelectContent,
GhostSelectOption,
GhostSelectTrigger,
GhostSelectValue,
} from '@ghostvue/themes'
const statuses = [
{ value: 'any', label: 'Any status' },
{ value: 'open', label: 'Open' },
{ value: 'paid', label: 'Paid' },
{ value: 'overdue', label: 'Overdue' },
] as const
const status = ref('any')
const search = ref('')
</script>
<template>
<!--
size="sm" on GhostSelectTrigger matches the small input and button in the
filter bar. The open list keeps its usual option size.
-->
<div class="filter-bar">
<GhostInput
v-model="search"
size="sm"
type="search"
aria-label="Search customers"
placeholder="Search customers"
/>
<GhostSelect v-model="status">
<GhostSelectTrigger size="sm" aria-label="Status">
<GhostSelectValue />
</GhostSelectTrigger>
<GhostSelectContent>
<GhostSelectOption
v-for="option in statuses"
:key="option.value"
:value="option.value"
>
{{ option.label }}
</GhostSelectOption>
</GhostSelectContent>
</GhostSelect>
<GhostButton size="sm" variant="ghost" tone="neutral">Clear</GhostButton>
</div>
</template>
<style scoped>
.filter-bar {
align-items: center;
display: flex;
flex-wrap: wrap;
gap: var(--ghost-space-gap-sm);
}
</style>