JGuang

Cascader

Cascader · Ant Design

Preview
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Cascader

Cascade selection box.

When To Use

  • When you need to select from a set of associated data set. Such as province/city/district, company level, things classification.
  • When selecting from a large data set, with multi-stage classifications separated for easy selection.
  • Chooses cascade items in one float layer for better user experience.

Examples

  • Basic · basic
  • Default value · default-value
  • Custom trigger · custom-trigger
  • Hover · hover
  • Disabled option · disabled-option
  • Change on select · change-on-select
  • Multiple · multiple
  • ShowCheckedStrategy · showCheckedStrategy
  • Size · size
  • Custom render · custom-render
  • Search · search
  • Load Options Lazily · lazy
  • Custom Field Names · fields-name
  • Prefix and Suffix · suffix
  • Custom dropdown · custom-dropdown
  • Placement · placement
  • Variants · variant
  • Status · status
  • Custom semantic dom styling · style-class
  • Panel · panel

API

Common props ref:Common props

<Cascader options={options} onChange={onChange} />
PropertyDescriptionTypeDefaultVersionGlobal Config
allowClearShow clear buttonboolean | { clearIcon?: ReactNode }true5.8.0: Support object typeclearIcon: 6.4.0
autoClearSearchValueWhether the current search will be cleared on selecting an item. Only applies when multiple is truebooleantrue5.9.0×
borderedWhether has border style, please use variant insteadbooleantrue-×
changeOnSelectChange value on each selection if set to true, see above demo for detailsbooleanfalse×
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-5.25.0
defaultOpenInitial visible of cascader popupboolean-×
defaultValueInitial selected valuestring[] | number[][]×
disabledWhether disabled selectbooleanfalse×
displayRenderThe render function of displaying selected options(label, selectedOptions) => ReactNodelabel => label.join(/)multiple: 4.18.0×
tagRenderCustom render function for tags in multiple mode(label: string, onClose: function, value: string) => ReactNode-×
popupClassNameThe additional className of popup overlay, use classNames.popup.root insteadstring-4.23.0×
dropdownClassNameThe additional className of popup overlay, please use classNames.popup.root insteadstring--×
dropdownRenderCustomize dropdown content, use popupRender instead(menus: ReactElement) => ReactNode-4.4.0×
popupRenderCustomize dropdown content(menus: ReactElement) => ReactNode-×
dropdownStyleThe style of dropdown menu, use styles.popup.root insteadCSSProperties-×
expandIconCustomize the current item expand iconReactNode-4.4.06.3.0
expandTriggerexpand current item when click or hover, one of click hoverstringclick×
fieldNamesCustom field name for label and value and childrenobject{ label: label, value: value, children: children }×
getPopupContainerParent Node which the selector should be rendered to. Default to body. When position issues happen, try to modify it into scrollable content and position it relative. examplefunction(triggerNode)() => document.body×
loadDataTo load option lazily, and it cannot work with showSearch(selectedOptions) => void-×
loadingIconCustomize the loading iconReactNode-6.3.0
maxTagCountMax tag count to show. responsive will cost render performancenumber | responsive-4.17.0×
maxTagPlaceholderPlaceholder for not showing tagsReactNode | function(omittedValues)-4.17.0×
maxTagTextLengthMax tag text length to shownumber-4.17.0×
notFoundContentSpecify content to show when no result matchesReactNodeNo data×
openSet visible of cascader popupboolean-4.17.0×
optionsThe data options of cascadeOption[]-×
placeholderThe input placeholderstring-×
placementUse preset popup align config from builtinPlacementsbottomLeft bottomRight topLeft topRightbottomLeft4.17.0×
prefixThe custom prefixReactNode-5.22.0×
showArrowWhether to show the arrow icon, please use suffixIcon={null} insteadbooleantrue-×
showSearchWhether show search input in single modeboolean | ObjectfalsesearchIcon: 6.4.0
sizeThe input sizelarge | medium | smallmedium×
statusSet validation status'error' | 'warning'-4.19.0×
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-5.25.0
suffixIconThe custom suffix iconReactNode-6.4.0
valueThe selected valuestring[] | number[]-×
variantVariants of selectoroutlined | borderless | filled | underlinedoutlined5.13.0 | underlined: 5.24.05.19.0
onChangeCallback when finishing cascader select(value, selectedOptions) => void-×
onClearCalled when clear() => void--×
onDropdownVisibleChangeCallback when popup shown or hidden, use onOpenChange instead(value) => void-4.17.0×
onOpenChangeCallback when popup shown or hidden(open: boolean) => void-×
onPopupVisibleChangeCallback when popup shown or hidden, please use onOpenChange instead(value) => void--×
multipleSupport multiple or notboolean-4.17.0×
removeIconThe custom remove iconReactNode-6.4.0
showCheckedStrategyThe way to show selected items in the box (only effective when multiple is true). Cascader.SHOW_CHILD: just show child treeNode. Cascader.SHOW_PARENT: just show parent treeNode (when all child treeNode under the parent treeNode are checked)Cascader.SHOW_PARENT | Cascader.SHOW_CHILDCascader.SHOW_PARENT4.20.0×
searchValueSet search value, Need work with showSearchstring-4.17.0×
onSearchThe callback function triggered when input changed(search: string) => void-4.17.0×
dropdownMenuColumnStyleThe style of the drop-down menu column, use styles.popup.listItem insteadCSSProperties-×
popupMenuColumnStyleThe style of the drop-down menu column, use styles.popup.listItem insteadCSSProperties-×
optionRenderCustomize the rendering dropdown options(option: Option) => React.ReactNode-5.16.0×

showSearch

PropertyDescriptionTypeDefaultVersion
autoClearSearchValueWhether the current search will be cleared on selecting an item. Only applies when multiple is truebooleantrue5.9.0
filterThe function will receive two arguments, inputValue and option, if the function returns true, the option will be included in the filtered set; Otherwise, it will be excludedfunction(inputValue, path): boolean-
limitSet the count of filtered itemsnumber | false50
matchInputWidthWhether the width of list matches input, (how it looks)booleantrue
renderUsed to render filtered optionsfunction(inputValue, path): ReactNode-
sortUsed to sort filtered optionsfunction(a, b, inputValue)-
searchValueSet search value, Need work with showSearchstring-4.17.0
onSearchThe callback function triggered when input changed(search: string) => void-4.17.0
searchIconCustomize the search iconReactNode-6.3.0

Option

interface Option {
  value: string | number;
  label?: React.ReactNode;
  disabled?: boolean;
  children?: Option[];
  // Determines if this is a leaf node(effective when `loadData` is specified).
  // `false` will force trade TreeNode as a parent node.
  // Show expand icon even if the current node has no children.
  isLeaf?: boolean;
}

Methods

NameDescriptionVersion
blur()Remove focus
focus()Get focus

Semantic DOM

Semantic nodeNative descriptionVersion
rootRoot element with relative positioning, inline-flex layout, cursor styles, transitions, border and other basic selector container styles—
prefixPrefix element with layout and styling for prefix content—
contentMultiple selection container with layout, spacing, and wrapping styles for selected items—
placeholderPlaceholder element with font styles and colors for placeholder text—
clearClear button element with layout, styling and interactive effects for clear button—
inputInput element with search input styling, cursor control, font inheritance and other search-related styles. Remove border styles—
suffixSuffix element with layout and styling for suffix content like clear button, arrow icon, etc.—
popup.rootPopup element with popup layer positioning, z-index, background, border, box-shadow and other popup container styles—
popup.listPopup list element with option list layout, scrolling, max-height and other list container styles—
popup.listItemPopup item element with option item padding, hover effects, selected states, disabled states and other option interactive styles—
itemMultiple selection item element with border, background, padding, and margin styles (multiple)—
itemContentMultiple selection item content area with text ellipsis styles (multiple)—
itemRemoveMultiple selection item remove button with font-related styles (multiple)—

Semantic description source: vendor/.dumi/theme/common/SelectSemanticTemplate.tsx

Design Token

Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.

TokenTypeNative description
controlWidthnumber | stringWidth of Cascader
controlItemWidthnumber | stringWidth of item
dropdownHeightnumber | stringHeight of dropdown
optionSelectedBgstringBackground color of selected item
optionSelectedColorstringText color when option is selected
optionSelectedFontWeightCSSProperties['fontWeight']Font weight of selected item
optionPaddingCSSProperties['padding']Padding of menu item
menuPaddingCSSProperties['padding']Padding of menu item (single column)

Declaration source: vendor/components/cascader/style/index.ts

import type { CSSProperties } from 'react';

import { genCompactItemStyle } from '../../style/compact-item';

import type { FullToken, GenerateStyle, GlobalToken } from '../../theme/internal';

import { genStyleHooks } from '../../theme/internal';

import getColumnsStyle from './columns';

export interface ComponentToken {
  /**
   * @desc 选择器宽度
   * @descEN Width of Cascader
   */
  controlWidth: number | string;
  /**
   * @desc 选项宽度
   * @descEN Width of item
   */
  controlItemWidth: number | string;
  /**
   * @desc 下拉菜单高度
   * @descEN Height of dropdown
   */
  dropdownHeight: number | string;
  /**
   * @desc 选项选中时背景色
   * @descEN Background color of selected item
   */
  optionSelectedBg: string;
  /**
   * @desc 选项选中时文本颜色
   * @descEN Text color when option is selected
   */
  optionSelectedColor: string;
  /**
   * @desc 选项选中时字重
   * @descEN Font weight of selected item
   */
  optionSelectedFontWeight: CSSProperties['fontWeight'];
  /**
   * @desc 选项内间距
   * @descEN Padding of menu item
   */
  optionPadding: CSSProperties['padding'];
  /**
   * @desc 选项菜单(单列)内间距
   * @descEN Padding of menu item (single column)
   */
  menuPadding: CSSProperties['padding'];
}

export type CascaderToken = FullToken<'Cascader'>;

Shared native props

Tips: The following generic properties apply to most antd components; those not supported are described separately.

PropertyDescriptionTypeDefault
styleThe additional styleCSSProperties-
classNameThe additional css classstring-
rootClassNameClassName on the root elementstring-
autoFocusAuto focus when component mounted, only effective for focusable elements like forms, links, etc.booleanfalse

Install and reproduce an example

npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.

Native type references

The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.

  • vendor/components/cascader/Panel.tsx
  • vendor/components/cascader/hooks/useIcons.tsx
  • vendor/components/cascader/index.tsx
  • vendor/components/cascader/style/index.ts

Source and license

https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd

Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.