Vitral 0.2
Form

CascadeSelect

A select for nested options, one column per level, opening each group beside the last.

Import

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

Basic

Value: null
<script setup lang="ts">import { CascadeSelect, Label, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const countries = [    {        name: 'Brazil',        states: [            { name: 'São Paulo', cities: [{ cname: 'São Paulo', code: 'SAO' }, { cname: 'Campinas', code: 'CPQ' }, { cname: 'Santos', code: 'SSZ' }] },            { name: 'Bahia', cities: [{ cname: 'Salvador', code: 'SSA' }, { cname: 'Porto Seguro', code: 'BPS' }] },            { name: 'Pernambuco', cities: [{ cname: 'Recife', code: 'REC' }, { cname: 'Olinda', code: 'OLI', disabled: true }] }        ]    },    {        name: 'Portugal',        states: [            { name: 'Lisboa', cities: [{ cname: 'Lisboa', code: 'LIS' }, { cname: 'Sintra', code: 'SNT' }] },            { name: 'Porto', cities: [{ cname: 'Porto', code: 'OPO' }, { cname: 'Matosinhos', code: 'MAT' }] }        ]    },    { name: 'Angola', states: [{ name: 'Luanda', cities: [{ cname: 'Luanda', code: 'LAD' }] }] }]; const city = ref<string | null>(null);</script> <template>    <StackPanel spacing="0.375rem" style="min-width: 16rem">        <Label for="cs-city">City</Label>        <CascadeSelect            id="cs-city"            v-model="city"            :options="countries"            option-label="cname"            option-value="code"            option-disabled="disabled"            option-group-label="name"            :option-group-children="['states', 'cities']"            placeholder="Select a city"            show-clear        />        <small style="color: var(--vt-text-muted-color)">Value: {{ city ?? 'null' }}</small>    </StackPanel></template>

Uneven depth

<script setup lang="ts">import { CascadeSelect, Label, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const menu = [    { label: 'Coffee', items: [{ label: 'Espresso' }, { label: 'Filter' }] },    { label: 'Tea', items: [{ label: 'Green', items: [{ label: 'Sencha' }, { label: 'Matcha' }] }, { label: 'Black' }] },    { label: 'Water' }]; const drink = ref<unknown>(null);</script> <template>    <StackPanel spacing="0.375rem" style="min-width: 16rem">        <Label for="cs-drink">Drink</Label>        <CascadeSelect id="cs-drink" v-model="drink" :options="menu" option-label="label" option-group-label="label" placeholder="Pick a drink" />    </StackPanel></template>

Sizes and states

<script setup lang="ts">import { CascadeSelect } from '@vitral/vue'; const menu = [    { label: 'Coffee', items: [{ label: 'Espresso' }, { label: 'Filter' }] },    { label: 'Tea', items: [{ label: 'Green', items: [{ label: 'Sencha' }, { label: 'Matcha' }] }, { label: 'Black' }] },    { label: 'Water' }];</script> <template>    <CascadeSelect :options="menu" option-label="label" option-group-label="label" placeholder="Small" size="small" aria-label="Small" />    <CascadeSelect :options="menu" option-label="label" option-group-label="label" placeholder="Filled" variant="filled" aria-label="Filled" />    <CascadeSelect :options="menu" option-label="label" option-group-label="label" placeholder="Invalid" invalid aria-label="Invalid" />    <CascadeSelect :options="menu" option-label="label" option-group-label="label" placeholder="Disabled" disabled aria-label="Disabled" /></template>

API

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

Props

NameTypeDescription
optionsany[]The top level; groups hold the next level in one of `optionGroupChildren`.
optionLabelstringField (dotted path) holding a choosable option's text.
optionValuestringField holding the value v-model receives. Without it, the whole option is the value.
optionDisabledstring—
optionGroupLabelstringField holding a group's text.
optionGroupChildrenstring | string[]The field, or the fields, one per level, that hold a group's children. Defaults to `items`.
dataKeystringCompare object values by this field instead of structurally.
placeholderstring—
showClearboolean—
loadingboolean—
emptyMessagestring—
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: { originalEvent?: Event; value: unknown }—
group-changeevent: { originalEvent?: Event; value: unknown }—
show——
hide——
focusevent: FocusEvent—
blurevent: FocusEvent—

Slots

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