Skip to content

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

Preview
当前值: 空
当前值: 空
当前值: 空

Installation

pnpm dlx brutx-vue@latest add cascader

Usage

Basic Usage

vue
<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.

vue
<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).

vue
<template>
    <Cascader
        v-model="selected"
        :options="options"
        check-strictly
        placeholder="Select any level"
    />
</template>

Props

Cascader

PropTypeDefaultDescription
optionsCascaderOption[][]Hierarchical options list
modelValueCascaderValue[] | CascaderValue[][][]Selected value path(s)
openbooleanControlled dropdown open state
multiplebooleanfalseEnable multiple path selections
clearablebooleanfalseDisplay clear selection button
checkStrictlybooleanfalseEnable selecting parent nodes (uncorrelated parent-child)
separatorstring' / 'Custom character separating paths
maxDisplaynumber2Max selected paths displayed in trigger before collapsing
size'sm' | 'default' | 'lg''default'Size of the trigger button
placeholderstringTrigger placeholder text
disabledbooleanfalseDisable component interaction
dropdownClassstringCustom CSS class for dropdown wrapper
ariaLabelstringARIA label
classstringCustom CSS class for trigger button

Events

EventParametersDescription
update:modelValueCascaderValue[] | CascaderValue[][]Emitted when value selection changes
update:openbooleanEmitted when open state changes, supporting v-model:open
changeCascaderValue[] | CascaderValue[][]Selection change event
open-changebooleanEmitted when dropdown state toggles

Data Types

ts
type CascaderValue = string | number

interface CascaderOption {
    value: CascaderValue
    label: string
    children?: CascaderOption[]
    disabled?: boolean
    data?: unknown
}

Exported Types

ts
import type { CascaderOption, CascaderValue } from 'brutx-ui-vue'

Accessibility

  • Keyboard Interaction:
    • ArrowDown / ArrowUp: Move focus up and down within the active column
    • ArrowRight: Expand the focused option's sub-column and focus the first item
    • ArrowLeft: Collapse the active sub-column, returning to parent option column
    • Enter / Space: Select option, or toggle Checkbox state in multi-select mode
    • Escape: Close dropdown panel
  • ARIA Attributes: The trigger has role="combobox", aria-expanded and aria-disabled indicators. Option items have role="menuitem"
  • Focus Management: Upon opening, the focus automatically moves to the last selected value's option item or the first item in the list. Restores focus back to the trigger on close
  • Reduced Motion: Transition animations support prefers-reduced-motion settings and automatically downgrade (if applicable)

Brute force builds.