Back to Ant Design

Cascader

components/cascader/index.en-US.md

6.3.79.3 KB
Original Source

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

<!-- prettier-ignore -->

<code src="./demo/basic.tsx">Basic</code> <code src="./demo/default-value.tsx">Default value</code> <code src="./demo/custom-trigger.tsx">Custom trigger</code> <code src="./demo/hover.tsx">Hover</code> <code src="./demo/disabled-option.tsx">Disabled option</code> <code src="./demo/change-on-select.tsx">Change on select</code> <code src="./demo/multiple.tsx">Multiple</code> <code src="./demo/showCheckedStrategy.tsx">ShowCheckedStrategy</code> <code src="./demo/size.tsx">Size</code> <code src="./demo/custom-render.tsx">Custom render</code> <code src="./demo/search.tsx">Search</code> <code src="./demo/lazy.tsx">Load Options Lazily</code> <code src="./demo/fields-name.tsx">Custom Field Names</code> <code src="./demo/suffix.tsx" version="5.22.0">Prefix and Suffix</code> <code src="./demo/custom-dropdown.tsx">Custom dropdown</code> <code src="./demo/placement.tsx">Placement</code> <code src="./demo/variant.tsx" version="5.13.0">Variants</code> <code src="./demo/status.tsx">Status</code> <code src="./demo/style-class.tsx" version="6.0.0">Custom semantic dom styling</code> <code src="./demo/panel.tsx" version=">= 5.10.0">Panel</code> <code src="./demo/ellipsis-debug.tsx" debug>Menu item ellipsis</code> <code src="./demo/render-panel.tsx" debug>_InternalPanelDoNotUseOrYouWillBeFired</code> <code src="./demo/component-token.tsx" debug>Component Token</code>

API

Common props ref:Common props

jsx
<Cascader options={options} onChange={onChange} />
PropertyDescriptionTypeDefaultVersion
allowClearShow clear buttonboolean | { clearIcon?: ReactNode }true5.8.0: Support object type
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
classNameThe additional css classstring-
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-
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: ReactNode) => ReactNode-4.4.0
popupRenderCustomize dropdown content(menus: ReactNode) => ReactNode-
dropdownStyleThe style of dropdown menu, use styles.popup.root insteadCSSProperties-
expandIconCustomize the current item expand iconReactNode-4.4.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-
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 matchesReactNodeNot Found
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 | Objectfalse
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>-
suffixIconThe custom suffix iconReactNode-
valueThe selected valuestring[] | number[]-
variantVariants of selectoroutlined | borderless | filled | underlinedoutlined5.13.0 | underlined: 5.24.0
onChangeCallback when finishing cascader select(value, selectedOptions) => void-
onDropdownVisibleChangeCallback when popup shown or hidden, use onOpenChange instead(value) => void-4.17.0
onOpenChangeCallback when popup shown or hidden(value) => void-
onPopupVisibleChangeCallback when popup shown or hidden, please use onOpenChange instead(value) => void--
multipleSupport multiple or notboolean-4.17.0
removeIconThe custom remove iconReactNode-
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

Option

typescript
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

<code src="./demo/_semantic.tsx" simplify="true"></code>

Design Token

<ComponentTokenTable component="Cascader"></ComponentTokenTable>