Skip to content

Repository files navigation

@rc-component/cascader

Ant Design Part of the Ant Design ecosystem.

🧭 React Cascader component for selecting values from hierarchical option trees, with search, multiple selection, async loading, and custom rendering.

NPM versionnpm downloadsbuild statusCodecovbundle sizedumi

English | 简体中文

Highlights

AreaSupport
DataNested options, field name mapping, disabled nodes
SelectionSingle, multiple, checkable, and change-on-select flows
SearchControlled search, custom filter, custom sort, custom render
LoadingAsync option loading with loadData
RenderingCustom option label, dropdown content, icons, and expand trigger

Install

npm install @rc-component/cascader

Usage

importCascaderfrom'@rc-component/cascader';constoptions=[{label: 'Zhejiang',value: 'zhejiang',children: [{label: 'Hangzhou',value: 'hangzhou',children: [{label: 'Xihu',value: 'xihu'}],},],},{label: 'Jiangsu',value: 'jiangsu',children: [{label: 'Nanjing',value: 'nanjing'}],},];exportdefault()=>(<Cascaderoptions={options}><buttontype="button">Please select</button></Cascader>);

Examples

Run the local dumi site:

npm install
npm start

Then open http://localhost:8000.

API

Cascader

PropertyTypeDefaultDescription
autoClearSearchValuebooleantrueDeprecated. Use showSearch.autoClearSearchValue instead.
builtinPlacementsBuildInPlacements-Custom popup placements.
changeOnSelectbooleanfalseTrigger onChange when selecting each level.
checkableboolean | ReactNodefalseEnable multiple selection with checkbox UI.
childrenReactElement-Trigger element.
classNamesSemantic class name map-Semantic class names for selector and popup elements.
defaultValuestring[] | number[] | Array<string[] | number[]>-Initial selected value.
displayRender(label, selectedOptions) => ReactNode-Render selected labels.
expandIconReactNode>Custom expand icon.
expandTriggerclick | hoverclickTrigger action for expanding the next option level.
fieldNames{ label?: string; value?: string; children?: string }{ label: 'label', value: 'value', children: 'children' }Custom option field names.
loadData(selectedOptions) => void-Load child options asynchronously.
loadingIconReactNode-Custom loading icon.
onChange(value, selectedOptions) => void-Called when selection changes.
onPopupVisibleChange(open: boolean) => void-Called when popup visibility changes.
onSearch(value: string) => void-Deprecated. Use showSearch.onSearch instead.
openboolean-Controlled popup visibility.
optionRender(option) => ReactNode-Custom option renderer.
optionsOption[]-Hierarchical option data.
placementSelect placement-Popup placement.
popupClassNamestring-Popup class name.
popupMenuColumnStyleCSSProperties-Style for each popup menu column.
prefixClsstringrc-cascaderClass name prefix.
searchValuestring-Deprecated. Use showSearch.searchValue instead.
showCheckedStrategySHOW_PARENT | SHOW_CHILDSHOW_PARENTStrategy for rendering checked values in multiple mode.
showSearchboolean | SearchConfigfalseEnable and configure search.
stylesSemantic style map-Semantic styles for selector and popup elements.
valuestring[] | number[] | Array<string[] | number[]>-Controlled selected value.

Cascader also accepts public props from @rc-component/selectBaseSelect, except private select-only props such as mode, labelInValue, showSearch, and tokenSeparators.

SearchConfig

PropertyTypeDefaultDescription
autoClearSearchValuebooleantrueClear search text after selecting an item.
filter(inputValue, options, fieldNames) => boolean-Return true to include an option path in search results.
limitnumber | false50Limit the number of filtered items.
matchInputWidthbooleantrueWhether the search result width matches the input width.
onSearch(value: string) => void-Called when search text changes.
render(inputValue, path, prefixCls, fieldNames) => ReactNode-Render a filtered option path.
searchValuestring-Controlled search text.
sort(a, b, inputValue, fieldNames) => number-Sort filtered option paths.

Option

PropertyTypeDefaultDescription
childrenOption[]-Child options.
disabledbooleanfalseDisable this option.
disableCheckboxbooleanfalseDisable this option's checkbox in multiple mode.
labelReactNode-Display label.
valuestring | number | null-Option value.

Development

npm install
npm start

The dumi site runs at http://localhost:8000 by default.

Common commands:

npm run lint
npm test
npm run tsc
npm run lint:tsc
npm run compile

Release

npm run prepublishOnly

The release flow is handled by @rc-component/np through the rc-np command after the package build.

License

@rc-component/cascader is released under the MIT license.

About

🧭 React Cascader component for selecting values from hierarchical option trees, with search, multiple selection, async loading, and custom rendering.

Topics

Resources

Stars

233 stars

Watchers

6 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages