Vitral 0.2
Form

MultiSelect

A select for several choices, shown as a list, a count or chips, with an optional filter.

Import

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

Basic

Value: SP
<script setup lang="ts">import { Label, MultiSelect, 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' }]; const selected = ref<string[]>(['SP']);</script> <template>    <StackPanel spacing="0.375rem" style="min-width: 16rem">        <Label for="ms-basic">Cities</Label>        <MultiSelect id="ms-basic" v-model="selected" :options="cities" option-label="name" option-value="code" option-disabled="disabled" placeholder="Select cities" :max-selected-labels="3" show-clear />        <small style="color: var(--vt-text-muted-color)">Value: {{ selected.join(', ') || '[]' }}</small>    </StackPanel></template>

Chips and filter

<script setup lang="ts">import { Label, MultiSelect, 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: 'Porto Alegre', code: 'POA' },    { name: 'Recife', code: 'REC' },    { name: 'Salvador', code: 'SSA' }]; const selected = ref<string[]>(['RJ', 'CWB']);</script> <template>    <StackPanel spacing="0.375rem" style="min-width: 22rem">        <Label for="ms-chips">Cities</Label>        <MultiSelect id="ms-chips" v-model="selected" :options="cities" option-label="name" option-value="code" display="chip" filter fluid placeholder="Select cities" />    </StackPanel></template>

Groups and a selection limit

<script setup lang="ts">import { Label, MultiSelect, 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 cities = [    { name: 'São Paulo', code: 'SP' },    { name: 'Rio de Janeiro', code: 'RJ' },    { name: 'Brasília', code: 'BSB' },    { name: 'Curitiba', code: 'CWB' },    { name: 'Recife', code: 'REC' }]; const grouped = ref<unknown[]>([]);const limited = ref<string[]>([]);</script> <template>    <StackPanel orientation="horizontal" spacing="0.75rem" align="start" wrap>        <StackPanel spacing="0.375rem" style="min-width: 16rem">            <Label for="ms-grouped">Cities by country</Label>            <MultiSelect id="ms-grouped" v-model="grouped" :options="groups" option-group-label="label" option-label="name" placeholder="Pick cities" />        </StackPanel>        <StackPanel spacing="0.375rem" style="min-width: 16rem">            <Label for="ms-limit">Up to two cities</Label>            <MultiSelect id="ms-limit" v-model="limited" :options="cities" option-label="name" option-value="code" :selection-limit="2" placeholder="Pick two" />        </StackPanel>    </StackPanel></template>

Sizes and states

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

API

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

Props

NameTypeDescription
optionsany[]—
optionLabelstringField (dotted path) holding an option's text. Without it, options are shown as they are.
optionValuestringField holding the value v-model collects. Without it, the whole option is the value.
optionDisabledstring—
optionGroupLabelstringTurns `options` into groups: this field is each group's label…
optionGroupChildrenstring…and this one its options. Defaults to `items`.
dataKeystringCompare object values by this field instead of structurally.
placeholderstring—
display'comma' | 'chip'How the choice is shown: a comma-separated list (the default) or chips.
maxSelectedLabelsnumberPast this many, the field says how many are chosen instead of naming them.
selectedItemsLabelstringWhat it says then. `{count}`; defaults to the locale's selection message.
selectionLimitnumberNo more than this many may be chosen.
showToggleAllbooleanShow the select-all box in the header. Defaults to true.
filterbooleanAdds a search box to the panel.
filterPlaceholderstring—
filterFieldsstring[]Fields to search instead of the label.
filterMatchModestringAny registered match mode; accent- and case-insensitive `contains` by default.
resetFilterOnHidebooleanEmpty the search box when the panel closes.
showClearboolean—
loadingboolean—
emptyMessagestring—
emptyFilterMessagestring—
disabledboolean—
invalidboolean—
sizeSize—
variantInputVariant—
fluidboolean—
placementOverlayPlacement—
appendTostring`'body'` (the default), `'self'` to render in place, or a selector.

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

Emits

EventPayloadDescription
changeevent: MultiSelectChangeEvent—
selectall-changeevent: { originalEvent: Event; checked: boolean }—
show——
hide——
filterquery: string—
focusevent: FocusEvent—
blurevent: FocusEvent—

Slots

NameSlot propsDescription
value(props: { value: unknown[]; options: unknown[]; placeholder?: string })The field's content.
option(props: { option: unknown; index: number; selected: boolean; focused: boolean })—
optiongroup(props: { group: unknown })—
header——
footer——
empty——
dropdownicon(props: { open: boolean })—