JGuang

Select

Select · Arco Design

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

Select

When users need to select one or more from a group of similar data, they can use Select to click and select the corresponding item.

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: Basic usage of Select.
  • Allow Clear: With built-in clear button.
  • Multiple Mode: Specify mode=multiple to use multiple selection. Set the maximum number of tags displayed through maxTagCount, and customize the rendering method of tags through the renderTag property to achieve more complex customization.
  • Front Label: Specify addBefore to add elements before the select box. (2.41.0)
  • Allow-Create: Specify allowCreate as true to create entries that do not exist in the options. Format user creations via allowCreate.formatter.
  • Search: Specify showSearch=true to search for the expanded options, and cooperate with filterOption to customize the search. When the search box is focused, the entered content will be cleared by default, however the content can be retained by specifying showSearch={ retainInputValue: true }.
  • Search Users: Through the combination of showSearch, filterOption and onSearch, you can search user from origin and select them.
  • Custom Popup Width: This example shows that the pop-up box can automatically adjust the width according to the content, and the minimum width is the width of the input box. The triggerProps.autoAlignPopupWidth property is to keep the width of popup box consistent with the input box. The triggerProps.autoAlignPopupMinWidth property is to keep the minimum width of the popup box consistent with the input box. They can be freely combined.
  • Size: Use size to select the size of Select (mini, small, default, large), the height corresponds to 24px, 28px, 32px, 36px.
  • Custom Selection Render: Use renderFormat to customize the content what will be rendered in select box. Note: In scenarios such as remote loading of option data, the corresponding option in value may not exist at some point. It is necessary to determine if the option does not exist, return the value as the displayed content.
  • With Group: Use Select.Group to group the drop-down menu options.
  • Specify Options: Specify optional options by passing in options.
  • Load Data While Scrolling: When loading dynamically, you can monitor scroll events through onPopupScroll.
  • Automatic Tokenization: Set tokenSeparators to use automatic word segmentation. Try copying Beijing,Shanghai,Shenzhen|Nanjing/Xi'an|Hangzhou into the input box. Only available in multiple mode.
  • Custom Trigger: Set triggerElement to customize the node that triggers the drop-down box. When the trigger element is customized, the shortcut key operation will not be available due to the invalidation of the internally bound keyboard processing functions, and additional processing needs to be performed through the hotkeyHandler.
  • Customize Dropdown: Use dropdownRender to freely customize the drop-down menu.
  • Borderless: Use bordered = false to use Select without borders.
  • Custom Tag Render: Use renderTag to customize Tags will be rendered in select box.
  • Coordinate: Coordinating the selection of provinces and cities is a common use case.
  • Hide Selected Items: Hide selected items in the drop-down menu.
  • Big Data: Select uses virtual-scrolling to ensure performance even in large amounts of data. When triggerProps.autoAlignPopupWidth = false and Option.label is a non-text type, virtual scrolling will be automatically closed because the maximum width of the option cannot be obtained when the option list is first rendered.
  • Draggable: In multiple mode, specify the dragToSort property to allow sort the entered values by dragging.
  • Auto Width: The width adaptation of Select can be set through the autoWidth property
  • Max tag count: The maximum number of tags for Select can be set through the maxTagCount property. When maxTagCount=responsive is used, the number of tags will be dynamically displayed based on the container size. Because it will monitor the size changes of all tags and containers, it is not recommended to use it when there are many options, as there may be performance issues.

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

Select

PropertyDescriptionTypeDefaultValueVersion
allowClearWhether allow to clear selected optionsboolean--
animationWhether to add animation for internal label changesbooleantrue2.15.0
borderedWhether to render borderbooleantrue-
defaultActiveFirstOptionWhether to highlight the first option by defaultbooleantrue-
defaultPopupVisibleWhether to show dropdown by default.boolean-2.14.0
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--
labelInValueWhether to embed label in value, turn the format of value from string to { value: string, label: ReactNode }boolean--
loadingWhether is in loadingboolean--
popupVisibleWhether to show dropdown.boolean-2.6.0
unmountOnExitWhether to destroy the DOM when hidingbooleantrue-
inputValueTo set input valuestring--
placeholderPlaceholder of elementstring--
allowCreateWhether to allow new options to be created by input.| boolean| {formatter: (inputValue: string, creating: boolean) => SelectProps['options'][number];}-2.13.0, { formatter } in 2.54.0
autoWidthauto width. minWidth defaults to 0, maxWidth defaults to 100%| boolean| { minWidth?: CSSProperties['minWidth']; maxWidth?: CSSProperties['maxWidth'] }-2.54.0
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;}-Object type in 2.37.0. responsive in 2.62.0
modeSet mode of Select(tags recommends using mode: multiple; allowCreate: true instead, this mode will be removed in the next major version)'multiple' | 'tags'--
sizeHeight of element, 24px 28px 32px 36px'mini' | 'small' | 'default' | 'large'--
statusStatus'error' | 'warning'-2.45.0
triggerThe trigger mode which executes the dropdown action.TriggerProps['trigger']click-
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
notFoundContentSpecify content to show when no result matches.ReactNode--
prefixCustomize select suffixReactNode-2.11.0
suffixIconCustomize select suffix iconReactNode--
arrowIconCustomize select arrow icon.ReactNode | null--
classNameAdditional css classstring | string[]--
defaultValueTo set default valuestring | string[] | number | number[] | LabeledValue | LabeledValue[]--
dropdownMenuClassNameThe className of dropdown menu.string | string[]--
dropdownMenuStyleThe style of dropdown menu.CSSProperties--
optionsSelect options(| string| number| { label: ReactNode | string; value: string | number; disabled?: boolean; extra?: any })[]-extra in 2.2.0
removeIconCustomize the delete icon of tags selected in multiple and label mode.ReactNode | null--
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.boolean | { retainInputValue?: boolean; retainInputValueWhileSelect?: boolean }--
styleAdditional styleCSSProperties--
tokenSeparatorsSeparator used to tokenize on multiple mode.string[]--
triggerPropsPass all Trigger component propertiesPartial<TriggerProps>--
valueTo set valuestring | string[] | number | number[] | LabeledValue | LabeledValue[]--
virtualListPropsPass properties used by VirtualList.AvailableVirtualListProps-2.1.0
dropdownRenderCustomize dropdown content(menu: ReactNode) => ReactNode--
filterOptionIf it's true, filter options by input value. If it's a function, filter options base on the function.boolean | ((inputValue: string, option: ReactElement) => boolean)true-
getPopupContainerTo set the container of the dropdown.(node: HTMLElement) => Element--
onBlurCallback when lose focus(e) => void--
onChangeCallback when select an option or input value change.(value, option: OptionInfo | OptionInfo[]) => void--
onClearCalled when clear(visible: boolean) => void--
onClickCallback when the mouse clicks on the drop-down box(e) => void--
onDeselectCalled when an option is deselected. Only called for multiple mode.(value: string | number | LabeledValue, option: OptionInfo) => void--
onFocusCallback when get focus(e) => void--
onInputValueChangeCallback when the value of input is changed.(value: string, reason: InputValueChangeReason) => void-2.3.0
onKeyDownCallback when keyboard pressed(e) => void-2.40.0
onPasteCallback when the you paste text in input box.(e) => void-2.9.0
onPopupScrollCallback when dropdown scrolls.(elem) => void--
onSearchCallback when input changed(value: string, reason: InputValueChangeReason) => void--
onSelectCalled when an option is selected. Only called for multiple mode.(value: string | number | LabeledValue, option: OptionInfo) => void-2.52.0
onVisibleChangeCallback when visibility of dropdown is changed.(visible: boolean) => void--
renderFormatCustomize the content that will be displayed in the Select.If the Option corresponding to value does not exist, the first parameter will be null(option: OptionInfo | null, value: string | number | LabeledValue) => 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
triggerElementThe trigger element which executes the dropdown action.| ReactNode| ((params: { value: any; option: OptionInfo | OptionInfo[] }) => ReactNode)-() => ReactNode in 2.31.0

Select.Option

PropertyDescriptionTypeDefaultValueVersion
disabledWhether the option is disabledboolean--
classNameAdditional css classstring | string[]--
extraAny data you want to pass to Option.any-2.2.0
styleAdditional styleCSSProperties--
valueValue of this Optionstring | number (Required)--

Select.OptGroup

PropertyDescriptionTypeDefaultValue
labelName of GroupReactNode-
classNameAdditional css classstring | string[]-
styleAdditional styleCSSProperties-

Select Reference Type

PropertyDescriptionTypeDefaultValueVersion
activeOptionValueThe value of active optionOptionProps['value'] (Required)--
getOptionInfoByValueGet the option info by its value(value: OptionProps['value']) => OptionInfo (Required)--
scrollIntoViewScroll the drop-down list to the specified option(value: OptionProps['value'], options?: ScrollIntoViewOptions) => void (Required)-2.46.0
domDOMHTMLDivElement (Required)--
blurBlur Select() => void (Required)--
focusFocus Select() => void (Required)--
getOptionInfoListGet the list of option info() => OptionInfo[] (Required)--
hotkeyHandlerProcessor of mouse shortcut operation(event: KeyboardEvent) => void (Required)--

LabeledValue

export type LabeledValue = {
  value: string | number;
  label: ReactNode;
};

OptionInfo

export interface OptionInfo extends PropsWithChildren<OptionProps> {
  child?: ReactElement;
  _valid: boolean;
  _index: number;
  _origin: "children" | "options" | "userCreatedOptions" | "userCreatingOption";
}

AvailableVirtualListProps

export type AvailableVirtualListProps = Pick<
  VirtualListProps<any>,
  | "height"
  | "itemHeight"
  | "threshold"
  | "isStaticItemHeight"
  | "scrollOptions"
  | "onScroll"
  | "wrapperChild"
>;

InputValueChangeReason

// 造成输入框值改变的原因:用户输入、选中选项、选项下拉框收起、触发自动分词
export type InputValueChangeReason =
  | "manual"
  | "optionChecked"
  | "optionListHide"
  | "tokenSeparator";

ObjectValueType

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

VirtualListProps

PropertyDescriptionTypeDefault
heightViewable area height (2.11.0 starts to support string type such as 80%)number200
thresholdThe threshold of the number of elements that automatically enable virtual scrolling, pass in null to disable virtual scrolling.number | null100
isStaticItemHeightWhether it is a static element of the same heightbooleantrue