Vitral 0.2.18
Form

Select

Choose one option from a list, with an optional filter that ignores case and accents.

Import

main.ts
import { Select } from '@vitral/vue';

Basic

Value: null
<script setup lang="ts">import { Label, Select, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const cities = [    { name: 'São Paulo', code: 'SP' },    { name: 'Rio de Janeiro', code: 'RJ' },    { name: 'Belo Horizonte', code: 'BH' },    { name: 'Brasília', code: 'BSB' },    { name: 'Curitiba', code: 'CWB' },    { name: 'Florianópolis', code: 'FLN', disabled: true },    { name: 'Porto Alegre', code: 'POA' },    { name: 'Recife', code: 'REC' },    { name: 'Salvador', code: 'SSA' },    { name: 'Manaus', code: 'MAO' }]; const city = ref<string | null>(null);</script> <template>    <StackPanel spacing="0.375rem" style="min-width: 16rem">        <Label for="sel-city">City</Label>        <Select id="sel-city" v-model="city" :options="cities" option-label="name" option-value="code" option-disabled="disabled" placeholder="Select a city" show-clear checkmark />        <small style="color: var(--vt-text-muted-color)">Value: {{ city ?? 'null' }}</small>    </StackPanel></template>

Filter

<script setup lang="ts">import { Label, Select, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const cities = [    { name: 'São Paulo', code: 'SP' },    { name: 'Rio de Janeiro', code: 'RJ' },    { name: 'Belo Horizonte', code: 'BH' },    { name: 'Brasília', code: 'BSB' },    { name: 'Curitiba', code: 'CWB' },    { name: 'Florianópolis', code: 'FLN' },    { name: 'Porto Alegre', code: 'POA' },    { name: 'Recife', code: 'REC' },    { name: 'Salvador', code: 'SSA' },    { name: 'Manaus', code: 'MAO' }]; const city = ref<string | null>('REC');</script> <template>    <StackPanel spacing="0.375rem" style="min-width: 16rem">        <Label for="sel-search">City (searchable)</Label>        <Select id="sel-search" v-model="city" :options="cities" option-label="name" option-value="code" filter placeholder="Search…" />    </StackPanel></template>

Groups

<script setup lang="ts">import { Label, Select, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const groups = [    { label: 'Brazil', items: [{ name: 'São Paulo' }, { name: 'Recife' }] },    { label: 'Portugal', items: [{ name: 'Lisboa' }, { name: 'Porto' }] },    { label: 'Angola', items: [{ name: 'Luanda' }] }]; const city = ref<unknown>(null);</script> <template>    <StackPanel spacing="0.375rem" style="min-width: 16rem">        <Label for="sel-group">City by country</Label>        <Select id="sel-group" v-model="city" :options="groups" option-group-label="label" option-label="name" placeholder="Pick a city" />    </StackPanel></template>

Sizes and states

<script setup lang="ts">import { Select } from '@vitral/vue'; const cities = [{ name: 'São Paulo' }, { name: 'Rio de Janeiro' }, { name: 'Brasília' }, { name: 'Curitiba' }, { name: 'Recife' }];</script> <template>    <Select :options="cities" option-label="name" placeholder="Small" size="small" aria-label="Small" />    <Select :options="cities" option-label="name" placeholder="Filled" variant="filled" aria-label="Filled" />    <Select :options="cities" option-label="name" placeholder="Invalid" invalid aria-label="Invalid" />    <Select :options="cities" option-label="name" placeholder="Loading" loading aria-label="Loading" />    <Select :options="cities" option-label="name" placeholder="Disabled" disabled aria-label="Disabled" /></template>

API

Read from packages/vue/src/components/Select/types.ts, so it says what the component actually accepts.

Props

NameTypeDescription
options any[]—
optionLabel stringField (dotted path) holding an option's text. Without it, options are shown as they are.
optionValue stringField holding the value v-model receives. Without it, the whole option is the value.
optionDisabled string—
optionGroupLabel stringTurns `options` into groups: this field is each group's label…
optionGroupChildren string…and this one its options. Defaults to `items`.
dataKey stringCompare object values by this field instead of structurally.
placeholder string—
disabled boolean—
invalid boolean—
size Size—
variant InputVariant—
fluid boolean—
filter booleanAdds a search box to the panel: the combobox.
filterPlaceholder string—
filterFields string[]Fields to search instead of the label.
filterMatchMode stringAny registered match mode; accent- and case-insensitive `contains` by default.
showClear boolean—
loading boolean—
checkmark booleanMarks the selected option with a check, as well as with the highlight.
emptyMessage string—
emptyFilterMessage string—
placement OverlayPlacement—
appendTo string`'body'` (the default), `'self'` to render in place, or a selector.
scrollbar ScrollbarModeThe bars of the boxes this component scrolls inside — `'hover'`, `'always'` or `'native'`. The application's `scrollbar` option by default, which is `'hover'`.

Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.

Emits

EventPayloadDescription
change event: SelectChangeEvent—
show ——
hide ——
filter query: string—
focus event: FocusEvent—
blur event: FocusEvent—

Slots

NameSlot propsDescription
value (props: { value: unknown; option: unknown; placeholder?: string })—
option (props: { option: unknown; index: number; selected: boolean; focused: boolean })—
optiongroup (props: { group: unknown })—
header ——
footer ——
empty ——
dropdownicon (props: { open: boolean })—