CascadeSelect

CascadeSelect is a form component to select a value from a nested structure of options.


import CascadeSelect from 'primevue/cascadeselect';

CascadeSelect is used as a controlled component with v-model property along with an options collection. To define the label of a group optionGroupLabel property is needed and also optionGroupChildren is required to define the property that refers to the children of a group. Note that order of the optionGroupChildren matters as it should correspond to the data hierarchy.

Select a City3 results are available

<CascadeSelect v-model="selectedCity" :options="countries" optionLabel="cname" optionGroupLabel="name"
    :optionGroupChildren="['states', 'cities']" style="min-width: 14rem" placeholder="Select a City" />

CascadeSelect is used as a controlled component with v-model property along with an options collection. To define the label of a group optionGroupLabel property is needed and also optionGroupChildren is required to define the property that refers to the children of a group. Note that order of the optionGroupChildren matters as it should correspond to the data hierarchy.

Select a City3 results are available

<CascadeSelect v-model="selectedCity" :options="countries" optionLabel="cname" optionGroupLabel="name"
    :optionGroupChildren="['states', 'cities']" style="min-width: 14rem" placeholder="Select a City">
    <template #option="slotProps">
        <div class="flex align-items-center">
            <img v-if="slotProps.option.states" :alt="slotProps.option.name" src="https://primefaces.org/cdn/primevue/images/flag/flag_placeholder.png" :class="`flag flag-${slotProps.option.code.toLowerCase()} mr-2`" style="width: 18px"  />
            <i v-if="slotProps.option.cities" class="pi pi-compass mr-2"></i>
            <i v-if="slotProps.option.cname" class="pi pi-map-marker mr-2"></i>
            <span>{{ slotProps.option.cname || slotProps.option.name }}</span>
        </div>
    </template>
</CascadeSelect>

Loading state can be used loading property.

Loading...No results found

<CascadeSelect loading placeholder="Loading..."  style="min-width: 14rem" />

A floating label appears on top of the input field when focused. Visit FloatLabel documentation for more information.

Select a City3 results are available

<FloatLabel>
    <CascadeSelect v-model="selectedCity" inputId="cs-city" :options="countries" optionLabel="cname" optionGroupLabel="name"
        :optionGroupChildren="['states', 'cities']" style="min-width: 14rem" placeholder="Select a City" />
    <label for="cs-city">City</label>
</FloatLabel>

Specify the variant property as filled to display the component with a higher visual emphasis than the default outlined style.

Select a City3 results are available

<CascadeSelect v-model="selectedCity" variant="filled" :options="countries" optionLabel="cname" optionGroupLabel="name"
    :optionGroupChildren="['states', 'cities']" style="min-width: 14rem" placeholder="Select a City" />

Invalid state is displayed using the invalid prop to indicate a failed validation. You can use this style when integrating with form validation libraries.

Select a City3 results are available

<CascadeSelect v-model="selectedCity" invalid :options="countries" optionLabel="cname" optionGroupLabel="name"
    :optionGroupChildren="['states', 'cities']" style="min-width: 14rem" placeholder="Select a City" />

When disabled is present, the element cannot be edited and focused.

DisabledNo results found

<CascadeSelect disabled placeholder="Disabled" style="min-width: 14rem" />

Screen Reader

Value to describe the component can either be provided with aria-labelledby or aria-label props. The cascadeselect element has a combobox role in addition to aria-haspopup and aria-expanded attributes. The relation between the combobox and the popup is created with aria-controls that refers to the id of the popup.

The popup list has an id that refers to the aria-controls attribute of the combobox element and uses tree as the role. Each list item has a treeitem role along with aria-label, aria-selected and aria-expanded attributes. The container element of a treenode has the group role. The aria-setsize, aria-posinset and aria-level attributes are calculated implicitly and added to each treeitem.


<span id="dd1"></span>Options</span>
<CascadeSelect aria-labelledby="dd1" />

<CascadeSelect aria-label="Options" />

Closed State Keyboard Support

KeyFunction
tabMoves focus to the cascadeselect element.
spaceOpens the popup and moves visual focus to the selected option, if there is none then first option receives the focus.
enterOpens the popup and moves visual focus to the selected option, if there is none then first option receives the focus.
down arrowOpens the popup and moves visual focus to the selected option, if there is none then first option receives the focus.
up arrowOpens the popup and moves visual focus to the selected option, if there is none then last option receives the focus.
any printable characterOpens the popup and moves focus to the option whose label starts with the characters being typed, if there is none then first option receives the focus.

Popup Keyboard Support

KeyFunction
tabHides the popup and moves focus to the next tabbable element. If there is none, the focusable option is selected and the overlay is closed then moves focus to next element in page.
shift + tabHides the popup and moves focus to the previous tabbable element.
enterSelects the focused option and closes the popup.
spaceSelects the focused option and closes the popup.
escapeCloses the popup, moves focus to the cascadeselect element.
down arrowMoves focus to the next option.
up arrowMoves focus to the previous option.
alt + up arrowSelects the focused option and closes the popup, then moves focus to the cascadeselect element.
right arrowIf option is closed, opens the option otherwise moves focus to the first child option.
left arrowIf option is open, closes the option otherwise moves focus to the parent option.
homeMoves input cursor at the end, if not then moves focus to the first option.
endMoves input cursor at the beginning, if not then moves focus to the last option.
any printable characterMoves focus to the option whose label starts with the characters being typed.