Components/Cascader
Universal Component

Cascader

Hierarchical single or multiple selector with local search and lazy child loading.

This page was migrated by AI, please review carefully

Migration is complete, but please validate against source code and manual review.

Cascader

TxCascader selects a path from nested options. Single mode stores one path array, while multiple mode stores an array of path arrays. Search is local to the loaded option tree; async children are loaded through load when a non-leaf node without children is expanded.

Basic Usage

Cascader

Demo will load when visible.
<script setup lang="ts">
import { ref } from 'vue'

const value1 = ref<any>(undefined)
const value2 = ref<any>([])

const options = [
  {
    value: 'zhejiang',
    label: 'Zhejiang',
    children: [
      {
        value: 'hangzhou',
        label: 'Hangzhou',
        children: [
          { value: 'xihu', label: 'West Lake', leaf: true },
          { value: 'binjiang', label: 'Binjiang', leaf: true },
        ],
      },
    ],
  },
  {
    value: 'jiangsu',
    label: 'Jiangsu',
    children: [
      {
        value: 'nanjing',
        label: 'Nanjing',
        children: [
          { value: 'zhonghuamen', label: 'Zhong Hua Men', leaf: true },
        ],
      },
    ],
  },
]
</script>

<template>
  <div style="display: flex; flex-direction: column; gap: 12px; width: 520px;">
    <div style="display: flex; gap: 12px; align-items: center;">
      <TxCascader v-model="value1" :options="options" placeholder="Single" />
      <TxCascader v-model="value2" :options="options" multiple placeholder="Multiple" />
    </div>

    <div style="color: var(--tx-text-color-secondary); font-size: 12px;">
      single: {{ value1 }}
    </div>
    <div style="color: var(--tx-text-color-secondary); font-size: 12px;">
      multiple: {{ value2 }}
    </div>
  </div>
</template>

Notes

  • Single-select modelValue is a path array; multi-select is an array of path arrays.
  • expandTrigger controls click/hover expansion (in hover mode, clicking non-leaf nodes will not expand).
  • Async load only triggers when a node has no children and is not marked leaf.

API

TxCascader Props

PropTypeDefaultDescription
modelValueCascaderValue-Selected value. Single mode uses one path array; multiple mode uses an array of path arrays.
optionsCascaderNode[][]Root option tree rendered by the cascader columns.
multiplebooleanfalseEnables selecting multiple leaf paths and renders selected paths as tags.
disabledbooleanfalseDisables the trigger, clear button, node selection, and keyboard open behavior.
placeholderstring'请选择'Placeholder text shown when no path is selected.
searchablebooleantrueShows a local search input that filters loaded leaf paths by formatted label.
clearablebooleantrueShows the clear button when a value is selected and the component is enabled.
placementPopoverPlacement'bottom-start'Placement forwarded to the underlying TxPopover.
dropdownOffsetnumber6Offset forwarded to the underlying TxPopover.
dropdownWidthnumber360Width forwarded to the underlying TxPopover.
dropdownMaxWidthnumber520Maximum width forwarded to the underlying TxPopover.
dropdownMaxHeightnumber340Maximum panel height in px.
expandTrigger'click' | 'hover' | 'both''both'Controls how non-leaf nodes expand; hover ignores click expansion for branch nodes.
load(node, level) => Promise<CascaderNode[]>-Lazily loads children for a non-leaf node that does not already provide children.

CascaderNode

FieldTypeDescription
valuestring | numberStable node key used to build selected paths.
labelstringText rendered in columns, selected tags, and local search results.
disabledbooleanPrevents expanding or selecting this node.
leafbooleanMarks the node as selectable and prevents lazy loading.
childrenCascaderNode[]Child nodes rendered in the next column when this branch is active.

CascaderValue

  • Single select: CascaderPath (Array<string | number>)
  • Multi select: CascaderPath[]

Events

EventParamsDescription
update:modelValue(v)Emitted with the next CascaderValue whenever selection or clear changes the value.
change(v)Mirrors value changes for consumers that do not use v-model.
open-Emitted after the dropdown opens.
close-Emitted after the dropdown closes.

Expose

NameTypeDescription
open()() => voidOpens the dropdown.
close()() => voidCloses the dropdown.
toggle()() => voidToggles the dropdown open state.
focus()() => voidFocuses the trigger element.
blur()() => voidBlurs the trigger element.
clear()() => voidClears to undefined in single mode or [] in multiple mode.
setValue(v)(v) => voidEmits update:modelValue and change with the supplied value.
getValue()() => anyReturns the current modelValue prop.