JGuang

Cascader

Cascader · Arco Design

Preview
npm install @arco-design/web-react@2.66.18

Cascader

Display options in a multi-level cascading dropdown component.

Install

npm install @arco-design/web-react@2.66.18

Import @arco-design/web-react/dist/css/arco.css at the entry and set the locale with ConfigProvider. React 19 projects must also import @arco-design/web-react/es/_util/react-19-adapter first, or imperative APIs such as Message and Modal cannot render.

Examples

  • Basic: The basic usage. If expandTrigger is 'hover', next level menu will be expanded when current option is hovered.
  • Allow clear: Allow clear.
  • Front label: Specify addBefore to add elements before the select box. (2.41.0)
  • Customize selected value: The return value will be displayed in the input box
  • Customize select box: children will override the default select box node.
  • Change on select: Each selection will change value if set to true. when mode=multiple, child node and parent node will not affect each other.
  • Multiple: Allow multiple selection. Set the 'checkedStrategy' property to set the data echo mode(2.31.0).
  • Search: Specify showSearch=true, you can enter text to search for options.
  • Customize search logic: Customize the search logic.
  • Load options lazily: Load options lazily with loadMore. Please note when you use loadMore: 1. Option should have the isLeaf property to indicate whether to continue loading options when clicked 2. If showSearch=true, only the loaded options will be applied search logic. 如果使用搜索功能,将只从已加载数据的label属性进行关键字匹配。
  • Option disabled: Specify the disabled field of an option as true to disable the option.
  • Controlled: Control the selected value.
  • Size: There are four sizes available: mini, small, default and large. Their heights are 24px, 28px, 32px, 36px.
  • Customize option: Customize option node.
  • Customize footer: Custom rendering the footer of each level menu 。
  • Show empty list: If you want to display the next level menu when an option's children is [], please specify showEmptyChildren=true.
  • Visibility of dropdown: Use popupVisible and onVisibleChange to control the visibility of the dropdown. More examples can be found in Trigger.
  • DropdownRender: Customize the popup content by dropdownRender
  • Custom field names.: Custom field name for label, value, isLeaf, disabled and children.
  • onSearch: Customize the search logic by onSearch. Whether to display all options in the search panel can be controlled via the showSearch.panelMode property.
  • Draggable: In multiple mode, specify the dragToSort property to allow sort the entered values by dragging.

Examples come from the official Arco Design repository (MIT) at the commit published as npm 2.66.18. Some use online images or upload endpoints; network requests are disabled in previews.

API

Cascader

PropertyDescriptionTypeDefaultValueVersion
allowClearWhether allow to clear selected optionsboolean--
animationWhether to add animation for internal label changesbooleantrue2.15.0
borderedWhether to render borderbooleantrue-
changeOnSelectEach selection will change valueif set to true.when mode=multiple, child node and parent node will not affect each other.boolean--
defaultActiveFirstOptionWhether to highlight the first option of search results by defaultbooleantrue2.37.0
defaultPopupVisibleWhether the popup is visible by defaultboolean--
disabledWhether is disabledboolean--
dragToSortWeather it is possible to sort tags by dragboolean-2.27.0
errorWhether the textarea is error.(Deprecated, removed in the next major version, use status='error' instead)boolean--
loadingWhether is in loadingboolean--
popupVisibleWhether the popup is visibleboolean--
showEmptyChildrenWhether to render the next level node when the children of the selected option is an empty arrayboolean--
unmountOnExitWhether destroy popup when hidden.boolean--
inputValueInput Valuestring-2.34.0
placeholderPlaceholder of elementstring--
autoWidthauto width. minWidth defaults to 0, maxWidth defaults to 100%| boolean| { minWidth?: CSSProperties['minWidth']; maxWidth?: CSSProperties['maxWidth'] }-2.54.0
checkedStrategyCustomize the return value<br/> parent:Only return the parent node when all child nodes are selected <br/> child: Return child nodes'parent' | 'child'child2.31.0
expandTriggerSet the way to display the next level menu. One of hover and click'click' | 'hover'click-
maxTagCountThe maximum number of tags is displayed, only valid in multiple and label mode. Setting the number of responsive responsive display tags is not recommended when there are many options, as there may be performance issues.| number| 'responsive'| {count: number | 'responsive';render?: (invisibleTagCount: number) => ReactNode;showPopover?: boolean | Partial<PopoverProps>;}-Object type in 2.37.0. responsive in 2.62.0
modeSet mode'multiple'--
showSearchWhether single mode Select is searchable. { retainInputValue: true } to retain the existing content when the search box is focused,{ retainInputValueWhileSelect: true } to retain the existing content when multiple selection is selected.{ panelMode: 'select' } Display options as a search panel (2.39.0)renderOption Custom rendering search option (2.39.0)| boolean| {panelMode?: 'cascader' | 'select';renderOption?: (inputValue: string,option: NodeProps<T>,options: extraOptions) => ReactNode;retainInputValue?: boolean;retainInputValueWhileSelect?: boolean;}--
sizeHeight of element, 24px 28px 32px 36px'mini' | 'small' | 'default' | 'large'--
statusStatus'error' | 'warning'-2.45.0
virtualListPropsvirtual list props. After virtual scrolling is enabled, there will be a default width for each column of cascading menus, which can be adjusted by dropdownMenuColumnStylePick<VirtualListProps<any>, 'threshold' | 'isStaticItemHeight'>-2.35.0
addBeforeThe label text displayed before (on the left side of) the select fieldReactNode-2.41.0
clearIconConfigure the icon of the clear button when allowClear.ReactNode-2.26.0
notFoundContentThe content to show when no result matchesReactNode--
prefixCustomize select suffixReactNode-2.11.0
suffixIconCustomize select suffix iconReactNode--
arrowIconCustomize select arrow icon.ReactNode | null--
classNameAdditional css classstring | string[]--
defaultValueInitial value(string | string[])[]--
dropdownMenuClassNameCustom dropdown list classnamestring | string[]-2.35.0
dropdownMenuColumnStyledropdown menu column styleCSSProperties-2.35.0
fieldNamesCustom field name for label, value, isLeaf, disabled and childrenFieldNamesTypeDefaultFieldNames-
filterOptionCustomize the search logic.(inputValue: string, option: NodeProps<T>) => boolean--
iconsIcon configuration.{loading?: ReactNode;checked?: ReactNode;next?: ReactNode;}-2.50.0
loadMoreTo load option lazily(pathValue: string[], level: number) => Promise<T[]>--
optionsThe data of optionsT[][]-
removeIconCustomize the delete icon of tags selected in multiple and label mode.ReactNode | null--
renderFooterCustom rendering the footer of each level menu.(level: number, activeOption: NodeProps<T> | null) => ReactNode--
renderOptionCustom rendering option(option: NodeProps<T>, level: number) => ReactNode--
styleAdditional styleCSSProperties--
triggerPropsAll Trigger component propsPartial<TriggerProps>--
valueTo set value(string | string[])[]--
dropdownColumnRenderCustomize columns of the menu.(menu: ReactNode, level: number) => ReactNode-2.15.0, level in 2.17.0
dropdownRenderCustomize the popup menu.(menu: ReactNode) => ReactNode-2.15.0
getPopupContainerParentNode which the selector should be rendered to.(node: HTMLElement) => Element--
onChangeCallback when finishing select.(value: (string | string[])[],selectedOptions,extra: { dropdownVisible?: boolean }) => void--
onClearCallback when click clear icon.(visible: boolean) => void--
onClickCallback when the mouse clicks on the drop-down box(e) => void--
onInputValueChangeCallback when inputValue change.(inputValue: string, reason: InputValueChangeReason) => void-2.34.0
onKeyDownCallback when keyboard pressed(e) => void-2.40.0
onSearchCallback when input changed.(reason in 2.34.0)(inputValue: string, reason: InputValueChangeReason) => void-2.20.0
onVisibleChangeCallback when popup shown or hidden.(visible: boolean) => void--
renderFormatThe return value will be displayed in the input box.(valueShow: any[], options?: OptionProps[]) => ReactNode--
renderTagCustom tag rendering, props is the current tag attribute, index is the order of the current tag, values is the value of all tags(props: {value: any;label: ReactNode;closable: boolean;onClose: (event) => void;},index: number,values: ObjectValueType[]) => ReactNode-index、values added in 2.15.0

extraOptions

export interface extraOptions {
  checked: boolean;
}

FieldNamesType

/**
 * fieldnames 属性类型
 */
export type FieldNamesType = {
  /* Custom field name for label */
  label?: string;
  /** Custom field name for value */
  value?: string;
  /** Custom field name for children */
  children?: string;
  /** Custom field name for disabled  */
  disabled?: string;
  /** Custom field name for isLeaf */
  isLeaf?: string;
};

OptionProps

export interface OptionProps {
  /**
   * @zh 选项的值
   * @en: the value of Option
   *
   */
  value?: string;
  /**
   * @zh 选项文本
   * @en option text
   */
  label?: string;
  /**
   * @zh 是否禁用该选项
   * @en whether to disabled
   */
  disabled?: boolean;
  /**
   * @zh 下一级选项
   * @en next level menu
   */
  children?: OptionProps[];
  /**
   * @zh 是否是叶子节点
   * @en Flag whether it is a leaf node
   */
  isLeaf?: boolean;
  /**
   * @zh 是否禁用复选框选中
   * @en Whether to disable the check box is selected
   * @version 2.21.0
   */
  disableCheckbox?: boolean;
  /**
   * @zh 其他字段
   * @en other fields
   */
  [key: string]: any;
}

InputValueChangeReason

// 造成输入框值改变的原因:用户输入、选项下拉框收起、其他
export type InputValueChangeReason =
  | "manual"
  | "optionListHide"
  | "optionChecked";

ObjectValueType

export type ObjectValueType = {
  value?: any;
  label?: ReactNode;
  closable?: boolean;
};

Methods

NameDescriptionTypeDefault Value
focusGet focusFunction-
blurRemove focusFunction-

Demo

<Cascader ref={(ref) => (this.select = ref)} />;

this.select.focus();
this.select.blur();