Components/Cascader

Cascader

A selector that picks one or more paths from hierarchical data.

VerifiedSince 0.3.4

Usage

Single and Multiple

A single selection is one path array; with multiple, the value is an array of paths.

Loading demo...

Release Policy

An admin flow: Cascader sets the scope, FlatSelect the policy, sliders the thresholds, and TagInput the labels.

Loading demo...

Best Practices

  • Keep hierarchies to two or three levels; use search or TreeSelect for deeper trees.
  • Keep value keys stable across releases: the value stores path keys, so renaming one breaks saved selections.
  • Mark terminal async nodes leaf: true; otherwise they call load instead of becoming selectable.
  • Persist full paths, not leaf ids, so labels can be rebuilt.
  • Keep a visible field label; don't rely on the placeholder.

API Reference

Props

PropTypeDefaultDescription
modelValueCascaderValue-One path in single mode; an array of paths in multiple mode.
optionsCascaderNode[][]The root option tree.
multiplebooleanfalseSelects multiple leaf paths, shown as tags.
disabledbooleanfalseBlocks opening, clearing, and selection.
placeholderstring'Please select'Text shown when nothing is selected.
searchablebooleantrueShows a search box that matches loaded leaf paths only.
clearablebooleantrueShows a clear button when enabled and a value is set.
placementPopoverPlacement'bottom-start'Root panel placement, forwarded to TxPopover.
dropdownOffsetnumber6Root panel offset, forwarded to TxPopover.
dropdownWidthnumber260Root panel width; child panels fit their content between 200px and dropdownMaxWidth.
dropdownMaxWidthnumber520Maximum panel width.
dropdownMaxHeightnumber340Maximum panel height in px.
expandTrigger'click' | 'hover' | 'both''both'Branch panels open on click with click, on hover otherwise; clicking a branch row always expands it.
load(node, level) => Promise<CascaderNode[]>-Loads children for a node that has no children and is not a leaf.

Events

EventParamsDescription
update:modelValue(v)Fires with the new value after a selection or clear.
change(v)Fires together with update:modelValue.
open-Fires after the dropdown opens.
close-Fires after the dropdown closes.

Exposed Methods

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

Types

EXAMPLE.TS
type CascaderPath = Array<string | number>
type CascaderValue = CascaderPath | CascaderPath[] | undefined // single | multiple

CascaderNode, one entry of options:

FieldTypeDescription
valuestring | numberNode key; paths are built from these.
labelstringText shown in rows, tags, and search results.
disabledbooleanPrevents expanding or selecting the node.
leafbooleanMarks a selectable end node and skips lazy loading.
childrenCascaderNode[]Child nodes, rendered in the panel anchored to this row.

Overview

  • Each level is its own floating panel, anchored right-start to the row that opened it and sized to its labels; only opened branches are mounted.
  • Hover travel, the outside-click exemption, and cascading close run on the anchor-delay service, as in TxDropdownSubmenu, safe triangle included.
  • The trigger is role="combobox"; each level is a role="listbox" of role="option" rows, and branch rows add aria-haspopup="listbox" and aria-expanded.
  • Keyboard: Up/Down move and wrap, Home/End jump to the ends, ArrowRight opens a branch and focuses its first row, ArrowLeft closes the level and returns focus. ArrowLeft at the root is not intercepted.
  • Every row on the trail to the open panel stays active.
  • A search query replaces the levels with a flat list of leaf paths; clearing it restores them.

Technologies

  • Source: packages/tuffex/packages/components/src/cascader/.
查看源码
packages/tuffex/packages/components/src/cascader/index.ts