Vitral 0.2.18
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
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 collects. 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—
display 'comma' | 'chip'How the choice is shown: a comma-separated list (the default) or chips.
maxSelectedLabels numberPast this many, the field says how many are chosen instead of naming them.
selectedItemsLabel stringWhat it says then. `{count}`; defaults to the locale's selection message.
selectionLimit numberNo more than this many may be chosen.
showToggleAll booleanShow the select-all box in the header. Defaults to true.
filter booleanAdds a search box to the panel.
filterPlaceholder string—
filterFields string[]Fields to search instead of the label.
filterMatchMode stringAny registered match mode; accent- and case-insensitive `contains` by default.
resetFilterOnHide booleanEmpty the search box when the panel closes.
showClear boolean—
loading boolean—
emptyMessage string—
emptyFilterMessage string—
disabled boolean—
invalid boolean—
size Size—
variant InputVariant—
fluid boolean—
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: MultiSelectChangeEvent—
selectall-change event: { originalEvent: Event; checked: boolean }—
show ——
hide ——
filter query: string—
focus event: FocusEvent—
blur event: 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 })—