Cascader

If the options have a clear hierarchical structure, Cascader can be used to view and select them.

Basic usage

There are two ways to expand child option items.

Disabled option

Disable an option by setting a disabled field in the option object.

Clearable

Set clearable attribute for el-cascader and a clear icon will appear when selected and hovered

Custom Clear Icon 2.11.0

You can customize the clear icon by setting the clear-icon attribute

Display only the last level

The input can display only the last level instead of all levels.

Multiple Selection

Add :props="props" in tag and set data props = { multiple: true } to use multiple selection.

Do:

vue
<template>
  <el-cascader :props="props" />
</template>

<script lang="ts" setup>
const props = { multiple: true }
</script>

Don't do:

vue
<template>
  <!--  Object literal binging here is invalid syntax for cascader  -->
  <el-cascader :props="{ multiple: true }" />
</template>

Select any level of options

In single selection, only the leaf nodes can be checked, and in multiple selection, check parent nodes will lead to leaf nodes be checked eventually. When enable this feature, it can make parent and child nodes unlinked and you can select any level of options.

Dynamic loading

Dynamic load its child nodes when checked a node.

Filterable

Search and select options with a keyword.

Custom option content

You can customize the content of cascader node.

Custom suggestion item 2.9.5

You can customize the filter suggestion item by suggestion-item slot. You'll have access to item in the scope, standing for the suggestion item.

Cascader panel

CascaderPanel is the core component of Cascader which has various of features such as single selection, multiple selection, dynamic loading and so on.

Custom Tag 2.10.3

You can customize tags.

Show Checked Strategy 2.10.5

Control how selected values are displayed in multiple selection mode.

Click to Check Node 2.10.5

Only using multiple or checkStrictly attributes.

You can add checkOnClickNode to be able to click on the node in addition with the prefix icon.
Toggle the visibility of the prefix with showPrefix.

Add checkOnClickLeaf to check only the leaf node (last children), enabled by default.

You can customize both the header and footer of the dropdown using slots.

Cascader API

Cascader Attributes

NameDescriptionTypeDefault
model-value / v-modelbinding valuestring / number /object
optionsdata of the options, the key of value and label can be customize by CascaderProps.object
propsconfiguration options, see the following CascaderProps table.object
sizesize of inputenum
placeholderplaceholder of inputstring
disabledwhether Cascader is disabledboolean
clearablewhether selected value can be clearedboolean
clear-icon 2.11.0custom clear icon componentstring / objectCircleClose
show-all-levelswhether to display all levels of the selected value in the inputbooleantrue
collapse-tagswhether to collapse tags in multiple selection modeboolean
collapse-tags-tooltipwhether show all selected tags when mouse hover text of collapse-tags. To use this, collapse-tags must be truebooleanfalse
max-collapse-tags-tooltip-height 2.10.2max height of collapse-tags tooltip.string / number
separatoroption label separatorstring' / '
filterablewhether the options can be searchedboolean
filter-methodcustomize search logic, the first parameter is node, the second is keyword, and need return a boolean value indicating whether it hits.Function
debouncedebounce delay when typing filter keyword, in millisecondsnumber300
before-filterhook function before filtering with the value to be filtered as its parameter. If false is returned or a Promise is returned and then is rejected, filtering will be abortedFunction
popper-classcustom class name for Cascader's dropdown and tags' tooltipstring''
popper-stylecustom style for Cascader's dropdown and tags' tooltipstring / object
teleportedwhether cascader popup is teleportedbooleantrue
effect 2.10.5tooltip theme, built-in theme: dark / lightenum / stringlight
tag-typetag typeenuminfo
tag-effect 2.7.8tag effectenumlight
validate-eventwhether to trigger form validationbooleantrue
max-collapse-tags 2.3.10The max tags number to be shown. To use this, collapse-tags must be truenumber1
empty-values 2.7.0empty values of component, see config-providerarray
value-on-clear 2.7.0clear return value, see config-providerstring / number / boolean / Function
persistent 2.7.8when dropdown is inactive and persistent is false, dropdown will be destroyedbooleantrue
fallback-placements 2.8.1list of possible positions for Tooltip popper.jsarray
placement 2.8.1position of dropdownenumbottom-start
popper-append-to-body deprecatedwhether to append the popper menu to body. If the positioning of the popper is wrong, you can try to set this prop to falsebooleantrue
show-checked-strategy 2.10.5strategy for displaying checked nodes in multiple selection mode. Use parent when you want things tidy. Use child when every single item mattersenumchild

Cascader Events

NameDescriptionType
changetriggers when the binding value changesFunction
expand-changetriggers when expand option changesFunction
blurtriggers when Cascader blursFunction
focustriggers when Cascader focusesFunction
clear 2.7.7triggers when the clear icon is clicked in a clearable SelectFunction
visible-changetriggers when the dropdown appears/disappearsFunction
remove-tagtriggers when remove tag in multiple selection modeFunction

Cascader Slots

NameDescriptionType
defaultthe custom content of cascader node, which are current Node object and node data respectively.object
emptycontent when there is no matched options.
prefix 2.9.4content as Input prefix
suggestion-item 2.9.5custom content for suggestion item when searchingobject
tag 2.10.3custom tags styleobject
header 2.10.5content at the top of the dropdown
footer 2.10.5content at the bottom of the dropdown

Cascader Exposes

NameDescriptionType
getCheckedNodesget an array of currently selected node,(leafOnly) whether only return the leaf checked nodes, default is falseFunction
cascaderPanelRefcascader panel refobject
togglePopperVisible 2.2.31toggle the visible type of popperFunction
contentRefcascader content refobject
presentText 2.8.4selected content textobject
focus 2.11.8focus the input elementFunction
blur 2.11.8blur the input elementFunction

CascaderPanel API

CascaderPanel Attributes

NameDescriptionTypeDefault
model-value / v-modelbinding valuestring/number/object
optionsdata of the options, the key of value and label can be customize by CascaderProps.object
propsconfiguration options, see the following CascaderProps table.object

CascaderPanel Events

NameDescriptionType
changetriggers when the binding value changesFunction
update:modelValuetriggers when the binding value changesFunction
expand-changetriggers when expand option changesFunction
closeclose panel event, provided to Cascader to put away the panel judgment.Function

CascaderPanel Slots

NameDescriptionType
defaultthe custom content of cascader node, which are current Node object and node data respectively.object
empty 2.8.3the content of the panel when there is no data.

CascaderPanel Exposes

NameDescriptionType
getCheckedNodesget an array of currently selected node,(leafOnly) whether only return the leaf checked nodes, default is falseFunction
clearCheckedNodesclear checked nodesFunction

CascaderProps

AttributeDescriptionTypeDefault
expandTriggertrigger mode of expanding optionsenumclick
multiplewhether multiple selection is enabledbooleanfalse
checkStrictlywhether checked state of a node not affects its parent and child nodesbooleanfalse
emitPathwhen checked nodes change, whether to emit an array of node's path, if false, only emit the value of node.booleantrue
lazywhether to dynamic load child nodes, use with lazyload attributebooleanfalse
lazyLoadmethod for loading child nodes data, only works when lazy is true. The reject parameter is supported after version 2.11.5.Function
valuespecify which key of node object is used as the node's valuestringvalue
labelspecify which key of node object is used as the node's labelstringlabel
childrenspecify which key of node object is used as the node's childrenstringchildren
disabledspecify which key of node object is used as the node's disabledstringdisabled
leafspecify which key of node object is used as the node's leaf fieldstringleaf
hoverThresholdhover threshold of expanding optionsnumber500
checkOnClickNode 2.10.5whether to check or uncheck node when clicking on the nodebooleanfalse
checkOnClickLeaf 2.10.5whether to check or uncheck node when clicking on leaf node (last children).booleantrue
showPrefix 2.10.5whether to show the radio or checkbox prefixbooleantrue

Type Declarations

Show declarations
ts
type CascaderNodeValue = string | number
type CascaderNodePathValue = CascaderNodeValue[]
type CascaderValue =
  | CascaderNodeValue
  | CascaderNodePathValue
  | (CascaderNodeValue | CascaderNodePathValue)[]

type Resolve = (data: any) => void

type ExpandTrigger = 'click' | 'hover'

type LazyLoad = (node: Node, resolve: Resolve, reject: () => void) => void

type isDisabled = (data: CascaderOption, node: Node) => boolean

type isLeaf = (data: CascaderOption, node: Node) => boolean

interface CascaderOption extends Record<string, unknown> {
  label?: string
  value?: CascaderNodeValue
  children?: CascaderOption[]
  disabled?: boolean
  leaf?: boolean
}

interface CascaderProps {
  expandTrigger?: ExpandTrigger
  multiple?: boolean
  checkStrictly?: boolean
  emitPath?: boolean
  lazy?: boolean
  lazyLoad?: LazyLoad
  value?: string
  label?: string
  children?: string
  disabled?: string | isDisabled
  leaf?: string | isLeaf
  hoverThreshold?: number
}

class Node {
  readonly uid: number
  readonly level: number
  readonly value: CascaderNodeValue
  readonly label: string
  readonly pathNodes: Node[]
  readonly pathValues: CascaderNodePathValue
  readonly pathLabels: string[]

  childrenData: ChildrenData
  children: Node[]
  text: string
  loaded: boolean
  /**
   * Is it checked
   *
   * @default false
   */
  checked: boolean
  /**
   * Used to indicate the intermediate state of unchecked and fully checked child nodes
   *
   * @default false
   */
  indeterminate: boolean
  /**
   * Loading Status
   *
   * @default false
   */
  loading: boolean

  // getter
  isDisabled: boolean
  isLeaf: boolean
  valueByOption: CascaderNodeValue | CascaderNodePathValue

  // method
  appendChild(childData: CascaderOption): Node
  calcText(allLevels: boolean, separator: string): string
  broadcast(): void
  emit(): void
  onParentCheck(checked: boolean): void
  onChildCheck(): void
  setCheckState(checked: boolean): void
  doCheck(checked: boolean): void
}

Node as CascaderNode

Source

ComponentStyleDocs

Contributors