Known category
Select one value from a short fixed list with keyboard typeahead.
Components / Forms
A select-only combobox with keyboard navigation and typeahead.
Last changed in version 0.14.2: Improve keyboard navigation, action feedback, and selected colors across Vue components.
bunx --bun @getweini/cli@latest add selectImport the files copied by the install command, then place the component in your Vue template. The text and values in the example belong to your app; change them to fit your task.
<script setup lang="ts">
import { ref } from 'vue'
import Select from './components/ui/select/Select.vue'
import SelectContent from './components/ui/select/SelectContent.vue'
import SelectOption from './components/ui/select/SelectOption.vue'
import SelectTrigger from './components/ui/select/SelectTrigger.vue'
import SelectValue from './components/ui/select/SelectValue.vue'
const country = ref<string>()
</script>
<template>
<label for="country">Country</label>
<Select id="country" v-model="country">
<SelectTrigger><SelectValue placeholder="Choose a country" /></SelectTrigger>
<SelectContent>
<SelectOption value="LU">Luxembourg</SelectOption>
<SelectOption value="BE">Belgium</SelectOption>
</SelectContent>
</Select>
</template>Arrow keys move through options without changing the value. Select with Enter or Space; Escape and Tab close without selecting. Give the field a label. With clearable enabled, the clear button replaces the chevron.
Select one value from a short fixed list with keyboard typeahead.
Allow the user to clear an already selected filter.
Compose the trigger and options from the public children.
<script setup lang="ts">
import { ref } from 'vue'
import Select from './components/ui/select/Select.vue'
import SelectContent from './components/ui/select/SelectContent.vue'
import SelectOption from './components/ui/select/SelectOption.vue'
import SelectTrigger from './components/ui/select/SelectTrigger.vue'
import SelectValue from './components/ui/select/SelectValue.vue'
const priority = ref<string>()
</script>
<template>
<label for="priority">Priority</label>
<Select id="priority" v-model="priority" name="priority" required>
<SelectTrigger><SelectValue placeholder="Choose priority" /></SelectTrigger>
<SelectContent>
<SelectOption value="normal">Normal</SelectOption>
<SelectOption value="urgent">Urgent</SelectOption>
</SelectContent>
</Select>
</template>The clear action needs its own accessible name.
<script setup lang="ts">
import { ref } from 'vue'
import Select from './components/ui/select/Select.vue'
const status = ref<string>()
const options = [
{ label: 'Open', value: 'open' },
{ label: 'Closed', value: 'closed' },
]
</script>
<template>
<label for="status">Status</label>
<Select
id="status"
v-model="status"
:options="options"
placeholder="Any status"
clearable
clear-label="Clear status"
/>
</template>Every public prop, model, event, slot, and exposed member of the installed Vue parts is listed below. “Not set” means you can leave that value out; “Required” means you must provide it. Native HTML attributes also work where the component uses a native element.
| Name | Type or signature | Default | What it does |
|---|---|---|---|
modelValuemodel | T | undefined | Not set | Current value. Use v-model to keep it in sync with your page. |
defaultValueprop | T | undefined | Not set | Starting value when the parent does not control the value. |
openmodel | boolean | undefined | Not set | Current open state. Use v-model:open to keep it in sync with your page. |
defaultOpenprop | boolean | undefined | Not set | Starting open state when the parent does not control open. |
disabledprop | boolean | undefined | Not set | Prevent interaction and show the disabled state. |
requiredprop | boolean | undefined | Not set | Ask the browser to require a value before form submission. |
invalidprop | boolean | undefined | Not set | Show the invalid state; also provide a visible error message. |
nameprop | string | undefined | Not set | Name used when this control submits a value with a form. |
formprop | string | undefined | Not set | Associate the control with a form by its ID. |
idprop | string | undefined | Not set | Give the control an ID so a label or description can refer to it. |
sizeprop | ControlSize | undefined | "md" | Choose the visual size. Medium is the usual default where available. |
gapprop | number | undefined | 12 | Space in pixels between the trigger and floating content. |
byprop | ((a: T, b: T) => boolean) | undefined | Not set | Compare two values when identity is not enough, such as object options. |
serializeprop | ((value: T) => string) | undefined | Not set | Turn a selected value into the string submitted with a form. |
optionsprop | readonly SelectOption<T>[] | undefined | Not set | Compatibility convenience. Compound SelectOption children remain the source of truth. |
messagesprop | SelectMessages | undefined | Not set | Supply the text this component displays for its built-in actions and states. |
placeholderprop | string | undefined | Not set | Hint shown when no value has been entered or selected. |
clearableprop | boolean | undefined | Not set | Show an action for clearing the selected value. |
clearLabelprop | string | undefined | Not set | Accessible name for the compatibility clear button, if messages.clearSelection is absent. |
changeevent | [value: T | undefined] | — | Emitted after this value or state changes. |
update:modelValueevent | [value: T | undefined] | — | Requests a new model value from the parent. |
update:openevent | [open: boolean] | — | Requests a new open value from the parent. |
openChangeevent | [open: boolean] | — | Emitted after this value or state changes. |
defaultslot | (() => unknown) | undefined | Optional | Content shown inside Select. |
prefixslot | (() => unknown) | undefined | Optional | Content shown before the main label or value. |
suffixslot | (() => unknown) | undefined | Optional | Content shown after the main label or value. |
errorslot | ((props: { message: string; messages: string[]; }) => unknown) | undefined | Optional | Content for the error area of Select. |
elementexposed | HTMLButtonElement | null | — | Reference to the underlying HTML element. |
focusexposed | () => void | undefined | — | Move keyboard focus to this control. |
openexposed | (last?: boolean) => Promise<void> | — | Open this component from application code. |
closeexposed | (restoreFocus?: boolean) => void | — | Close this component from application code. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
widthprop | string | number | undefined | "trigger" | Choose the width of this content. |
defaultslot | () => unknown | Required | Content shown inside SelectContent. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
defaultslot | () => unknown | Required | Content shown inside SelectGroup. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
defaultslot | () => unknown | Required | Content shown inside SelectLabel. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
valueprop | T | Required | Value represented by this control or option. |
disabledprop | boolean | undefined | Not set | Prevent interaction and show the disabled state. |
textValueprop | string | undefined | Not set | Plain text used for search, typeahead, or an accessible label. |
labelprop | string | undefined | Not set | Visible or accessible name for this item. |
defaultslot | () => unknown | Required | Content shown inside SelectOption. |
indicatorslot | (() => unknown) | undefined | Optional | Content for the indicator area of SelectOption. |
| Name | Type or signature | Default | What it does |
|---|
| Name | Type or signature | Default | What it does |
|---|---|---|---|
sizeprop | ControlSize | undefined | Not set | Choose the visual size. Medium is the usual default where available. |
showIndicatorprop | boolean | undefined | true | Hide the default chevron when supplying a different trailing action. |
defaultslot | () => unknown | Required | Content shown inside SelectTrigger. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
placeholderprop | string | undefined | Not set | Hint shown when no value has been entered or selected. |
defaultslot | ((props: { value: unknown; option: unknown; }) => unknown) | undefined | Optional | Content shown inside SelectValue. |
placeholderslot | (() => unknown) | undefined | Optional | Content for the placeholder area of SelectValue. |
// packages/frameworks/vue/components/select/types.ts
// ------- IMPORTS -------
import type { ControlSize, SelectOption as LegacySelectOption } from '@getweini/vue/types'
// ------- TYPES -------
export type SelectValueType = string | number
export interface SelectMessages {
listboxLabel: string
empty: string
clearSelection: string
}
export interface SelectProps<T = SelectValueType> {
modelValue?: T
defaultValue?: T
open?: boolean
defaultOpen?: boolean
disabled?: boolean
required?: boolean
invalid?: boolean
name?: string
form?: string
id?: string
size?: ControlSize
gap?: number
by?: (a: T, b: T) => boolean
serialize?: (value: T) => string
/** Compatibility convenience. Compound SelectOption children remain the source of truth. */
options?: readonly LegacySelectOption<T>[]
messages?: SelectMessages
placeholder?: string
clearable?: boolean
/** Accessible name for the compatibility clear button, if messages.clearSelection is absent. */
clearLabel?: string
}
export interface SelectTriggerProps {
size?: ControlSize
/** Hide the default chevron when supplying a different trailing action. */
showIndicator?: boolean
}
export interface SelectValueProps {
placeholder?: string
}
export interface SelectContentProps {
width?: 'trigger' | string | number
}
export interface SelectOptionProps<T = SelectValueType> {
value: T
disabled?: boolean
textValue?: string
label?: string
}
// ------- EXPORTS -------
export type SelectOption<T = unknown> = LegacySelectOption<T>
// packages/frameworks/vue/dist/types/index.d.ts
export type { ButtonOptions, ButtonProps } from './button';
export type ControlSize = 'sm' | 'md' | 'lg';
export interface SelectOption<T = unknown> {
label: string;
value: T;
disabled?: boolean;
}
/** Application-owned copy. Bind translated strings reactively when the locale changes. */
export interface ListboxMessages {
/** Popup name when no aria-label or aria-labelledby is supplied. */
listboxLabel: string;
empty: string;
clearSelection: string;
}
export interface ListboxProps<T> {
options: readonly SelectOption<T>[];
messages: ListboxMessages;
id?: string;
disabled?: boolean;
required?: boolean;
invalid?: boolean;
name?: string;
form?: string;
placeholder?: string;
size?: ControlSize;
clearable?: boolean;
gap?: number;
/** Supply stable equality for object values. Values must be unique. */
by?: (a: T, b: T) => boolean;
/** Required for meaningful form submission of object values. */
serialize?: (value: T) => string;
}
// packages/frameworks/vue/dist/types/button.d.ts
import type { Component } from 'vue';
/** Options shared by button implementations across frameworks. */
export interface ButtonOptions<Variant extends string = string, Size extends string = string> {
variant?: Variant;
size?: Size;
disabled?: boolean;
loading?: boolean;
type?: 'button' | 'submit' | 'reset';
}
/** Vue-specific target options extend the reusable button contract. */
export interface ButtonProps<Variant extends string = 'default' | 'secondary' | 'outline' | 'ghost' | 'destructive', Size extends string = 'sm' | 'md' | 'lg'> extends ButtonOptions<Variant, Size> {
as?: 'button' | 'a' | Component;
asChild?: boolean;
}