Skip to content

Repository files navigation

@rc-component/select

Ant Design Part of the Ant Design ecosystem.

🎯 Composable Select component for React, with search, async-friendly option data, custom rendering, and virtual scrolling.

NPM versionnpm downloadsbuild statusCodecovbundle sizedumi

English | 简体中文

Highlights

AreaSupport
Dataoptions data, legacy Option children, grouped options
ModesSingle select, multiple, tags, and combobox
SearchControlled search, custom filter, custom sort
RenderingCustom option, label, selected item, clear, and menu icons
ScaleVirtual scrolling with configurable item height

Install

npm install @rc-component/select

Usage

importSelectfrom'@rc-component/select';import'@rc-component/select/assets/index.css';exportdefault()=>(<Selectplaceholder="Select a user"options={[{value: 'jack',label: 'Jack'},{value: 'lucy',label: 'Lucy'},{value: 'yiminghe',label: 'Yiminghe'},]}/>);

Examples

Run the local dumi site:

npm install
npm start

Then open http://localhost:8000.

API

Select

Select also accepts public props from BaseSelect, except showSearch, which is redefined by Select.

NameDescriptionTypeDefault
autoClearSearchValueDeprecated. Use showSearch.autoClearSearchValue instead.booleantrue
backfillBackfill the active option into the input. Only works in combobox mode.booleanfalse
childrenLegacy option children. Prefer options for new code.ReactNode-
classNamesSemantic class names.Partial<Record<SemanticName, string>>-
defaultActiveFirstOptionWhether the first option is active by default.booleantrue
defaultValueInitial selected value.ValueType | null-
directionDropdown direction.ltr | rtlltr
fieldNamesCustomize option field names.FieldNames-
filterOptionDeprecated. Use showSearch.filterOption instead.boolean | FilterFunc<OptionType>-
filterSortDeprecated. Use showSearch.filterSort instead.(optionA, optionB, info) => number-
labelInValueReturn labeled value objects instead of raw values.booleanfalse
labelRenderCustom selected label render.(props: LabelInValueType) => ReactNode-
listHeightPopup list height.number200
listItemHeightPopup list item height.number20
maxCountMaximum selected item count.number-
menuItemSelectedIconCustom selected option icon.RenderNode-
modeSelect mode.combobox | multiple | tags-
onActiveCalled when the active value changes.(value: ValueType) => void-
onChangeCalled when selected value changes.(value: ValueType, option?: OptionType | OptionType[]) => void-
onDeselectCalled when a value is deselected.(value, option) => void-
onSearchDeprecated. Use showSearch.onSearch instead.(value: string) => void-
onSelectCalled when a value is selected.(value, option) => void-
optionFilterPropDeprecated. Use showSearch.optionFilterProp instead.string | string[]-
optionLabelPropOption prop used as the selected label.string-
optionRenderCustom option renderer.(oriOption, info: { index: number }) => ReactNode-
optionsOption data.OptionType[]-
searchValueDeprecated. Use showSearch.searchValue instead.string-
showSearchEnable search or configure search behavior.boolean | SearchConfig<OptionType>-
stylesSemantic styles.Partial<Record<SemanticName, CSSProperties>>-
valueControlled selected value.ValueType | null-
virtualDisable virtual scrolling when set to false.booleantrue

Methods

NameDescriptionParameters
blurRemove focus.-
focusFocus the selector.-

SearchConfig

NameDescriptionTypeDefault
autoClearSearchValueClear search input after selecting or deselecting in multiple mode.booleantrue
filterOptionFilter options by search input.boolean | FilterFunc<OptionType>-
filterSortSort filtered options.(optionA, optionB, info: { searchValue: string }) => number-
onSearchCalled when search input changes.(value: string) => void-
optionFilterPropOption prop used for filtering when filterOption is enabled.string | string[]-
searchValueControlled search input value.string-

Option

Option is a legacy placeholder component. Prefer the options prop for new usage.

NameDescriptionTypeDefault
childrenOption label.ReactNode-
classNameOption class name.string-
disabledDisable the option.booleanfalse
titleOption title.string-
valueOption value.string | number | null-

OptGroup

OptGroup is a legacy placeholder component. Prefer nested options data for new usage.

NameDescriptionTypeDefault
childrenGroup options.ReactNode-
classNameGroup class name.string-
disabledDisable the group.booleanfalse
labelGroup label.ReactNode-
titleGroup title.string-

Development

npm install
npm start
npm test
npm run lint
npm run tsc
npm run compile

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

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/select is released under the MIT license.

About

🎯 Composable Select component for React, with search, async-friendly option data, custom rendering, and virtual scrolling.

Topics

Resources

Stars

936 stars

Watchers

26 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages