Cascader
A Neo-Brutalist styled cascading dropdown selection component. It displays multi-level hierarchical options in grid-cascaded panels, supporting path binding (single/multiple select), parent-child relation control, and complete keyboard interactions.
Preview
Installation
pnpm dlx brutx-vue@latest add cascaderUsage
Basic Usage
<script setup>
import { ref } from 'vue'
import { Cascader } from 'brutx-ui-vue'
const options = [
{
value: 'us',
label: 'USA',
children: [
{
value: 'ny',
label: 'New York',
children: [
{ value: 'man', label: 'Manhattan' },
{ value: 'qns', label: 'Queens' },
]
},
{
value: 'ca',
label: 'California',
}
]
},
{
value: 'cn',
label: 'China',
children: [
{ value: 'bj', label: 'Beijing' },
{ value: 'sh', label: 'Shanghai' },
]
}
]
const selected = ref([])
</script>
<template>
<Cascader
v-model="selected"
:options="options"
placeholder="Select region"
clearable
/>
</template>Multiple Selection
Set the multiple attribute to enable multi-select. The v-model bound value will be a two-dimensional array representing the selected full path arrays. By default, checking a parent node checks all its descendant leaf nodes.
<script setup>
import { ref } from 'vue'
import { Cascader } from 'brutx-ui-vue'
const selected = ref([]) // e.g. [['us', 'ny', 'man'], ['cn', 'bj']]
</script>
<template>
<Cascader
v-model="selected"
:options="options"
multiple
placeholder="Select multiple regions"
/>
</template>Check Strictly (Any level selection)
By default, only leaf nodes can be selected. Set checkStrictly to true to allow selecting nodes of any level (parent nodes can be bound as paths).
<template>
<Cascader
v-model="selected"
:options="options"
check-strictly
placeholder="Select any level"
/>
</template>API Reference
| Name | Type | Default | Description |
|---|---|---|---|
optionsRequired | CascaderOption<unknown>[] | — | The nested option tree for cascading selection; each option uses value and label and may include children. |
DetailsDeclared typeCascaderOption<unknown>[] Referenced types CascaderOption Type definition — CascaderOptionexport interface CascaderOption<T = unknown> {
value: CascaderValue
label: string
children?: CascaderOption<T>[]
disabled?: boolean
data?: T
}Default value details
Sourcepackages/ui/src/components/cascader/Cascader.vue | |||
modelValue | CascaderValue[] | CascaderValue[][] | undefined | []Factory evaluated per instance | The selected paths, bound with v-model. Single mode uses one CascaderValue path; multiple mode uses an array of paths. |
DetailsDeclared typeCascaderValue[] | CascaderValue[][] | undefined Referenced types CascaderValue Type definition — CascaderValueexport type CascaderValue = string | number Default value details
Sourcepackages/ui/src/components/cascader/Cascader.vue | |||
open | boolean | undefined | undefined | The controlled open state of the dropdown panel, synchronized with v-model:open. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/cascader/Cascader.vue | |||
multiple | boolean | undefined | false | Allows selecting multiple option paths; modelValue is an array of paths when enabled. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/cascader/Cascader.vue | |||
clearable | boolean | undefined | false | Shows a clear action for removing the selected paths. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/cascader/Cascader.vue | |||
checkStrictly | boolean | undefined | false | Allows parent nodes with children to be selected without requiring a leaf node. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/cascader/Cascader.vue | |||
separator | string | undefined | " / " | Sets the separator displayed between labels in a path on the trigger. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/cascader/Cascader.vue | |||
maxDisplay | number | undefined | 2 | In multiple mode, the maximum number of paths shown directly in the trigger; remaining paths are collapsed into a summary. |
DetailsDeclared typenumber | undefined Default value details
Sourcepackages/ui/src/components/cascader/Cascader.vue | |||
size | "default" | "lg" | "sm" | undefined | "default" | Sets the trigger button size variant. |
DetailsDeclared type"default" | "lg" | "sm" | undefined Literal values
Default value details
Sourcepackages/ui/src/components/cascader/Cascader.vue | |||
placeholder | string | undefined | undefined | Text shown in the trigger when no path is selected. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/cascader/Cascader.vue | |||
disabled | boolean | undefined | false | Disables user interaction with the select trigger and dropdown panel. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/cascader/Cascader.vue | |||
dropdownClass | string | undefined | undefined | CSS classes added to the cascader dropdown panel. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/cascader/Cascader.vue | |||
class | string | undefined | undefined | CSS classes added to the select trigger button. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/cascader/Cascader.vue | |||
ariaLabel | string | undefined | undefined | Sets the accessible label for the select trigger. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/cascader/Cascader.vue | |||
| Name | Signature or type | Description |
|---|---|---|
@update:modelValue | [value: CascaderValue[] | CascaderValue[][]] | Emits the updated path value when selection changes, for synchronizing the controlled value with v-model. |
DetailsDeclared type[value: CascaderValue[] | CascaderValue[][]] Referenced types CascaderValue Type definition — CascaderValueexport type CascaderValue = string | number Sourcepackages/ui/src/components/cascader/Cascader.vue | ||
@update:open | [value: boolean] | Emits the new boolean when the dropdown open state changes and can be used with v-model:open. |
DetailsDeclared type[value: boolean] Literal values
Sourcepackages/ui/src/components/cascader/Cascader.vue | ||
@change | [value: CascaderValue[] | CascaderValue[][]] | Emits the selected single path or set of paths when the user changes the selection. |
DetailsDeclared type[value: CascaderValue[] | CascaderValue[][]] Referenced types CascaderValue Type definition — CascaderValueexport type CascaderValue = string | number Sourcepackages/ui/src/components/cascader/Cascader.vue | ||
@open-change | [open: boolean] | Emits the current open state when the dropdown panel opens or closes. |
DetailsDeclared type[open: boolean] Literal values
Sourcepackages/ui/src/components/cascader/Cascader.vue | ||
Data Types
type CascaderValue = string | number
interface CascaderOption<T = unknown> {
value: CascaderValue
label: string
children?: CascaderOption<T>[]
disabled?: boolean
data?: T
}CascaderOption supports a generic for the business data type: in CascaderOption<MyData>[] the data field gets type inference; it defaults to unknown to stay permissive.
Exported Types
import type { CascaderOption, CascaderValue } from 'brutx-ui-vue'Accessibility
- Keyboard Interaction:
ArrowDown/ArrowUp: Move focus up and down within the active column, skippingdisabledoptionsArrowRight: Expand the focused option's sub-column and focus the first itemArrowLeft: Collapse the active sub-column, returning to parent option columnEnter/Space: Select option, or toggle Checkbox state in multi-select modeEscape: Close dropdown panel
- ARIA Attributes: The trigger has
role="combobox",aria-expandedandaria-disabledindicators. Option items haverole="menuitem" - Focus Management: Upon opening, focus moves to the last selected value's option item; with no selected value no item is highlighted (
aria-activedescendantstays undefined) until keyboard navigation begins, avoiding misreporting the first option while focus is still on the trigger - Reduced Motion: Transition animations support
prefers-reduced-motionsettings and automatically downgrade (if applicable)