JGuang

Select

Select · Ant Design

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

Select

A dropdown menu for displaying choices.

When To Use

  • A dropdown menu for displaying choices - an elegant alternative to the native <select> element.
  • Utilizing Radio is recommended when there are fewer total options (less than 5).
  • You probably need AutoComplete if you're looking for an input box that can be typed or selected.

Examples

  • Basic Usage · basic

  • Select with search field · search

  • Custom Search · search-filter-option

  • Multi field search · search-multi-field

  • multiple selection · multiple

  • Sizes · size

  • Custom dropdown options · option-render

  • Search with sort · search-sort

  • Tags · tags

  • Option Group · optgroup

  • coordinate · coordinate

  • Get value of selected item · label-in-value

  • Automatic tokenization · automatic-tokenization

  • Custom tokenization · custom-tokenization

  • Search and Select Users · select-users

  • Prefix and Suffix · suffix

  • Custom dropdown · custom-dropdown-menu

  • Hide Already Selected · hide-selected

  • Variants · variant

  • Custom Tag Render · custom-tag-render

  • Custom Selected Label Render · custom-label-render

  • Responsive maxTagCount · responsive

  • Big Data · big-data

  • Status · status

  • Placement · placement

  • Max Count · maxCount

  • Custom semantic dom styling · style-class

API

Common props ref:Common props

Select props

PropertyDescriptionTypeDefaultVersionGlobal Config
allowClearCustomize clear iconboolean | { clearIcon?: ReactNode }false5.8.0: Support object type6.4.0
autoClearSearchValueWhether the current search will be cleared on selecting an item. Only applies when mode is set to multiple or tagsbooleantrue×
borderedWhether has border style, please use variant insteadbooleantrue-×
classNamesCustomize class for each semantic structure inside the Select component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-5.25.0
defaultActiveFirstOptionWhether active first option by defaultbooleantrue×
defaultOpenInitial open state of dropdownboolean-×
defaultValueInitial selected optionstring | string[] | <br />number | number[] | <br />LabeledValue | LabeledValue[]-×
disabledWhether disabled selectbooleanfalse×
dropdownClassNameThe className of dropdown menu, please use classNames.popup.root insteadstring--×
dropdownMatchSelectWidthDetermine whether the popup menu and the select input are the same width, please use popupMatchSelectWidth insteadboolean | numbertrue-×
popupClassNameThe className of dropdown menu, use classNames.popup.root insteadstring-4.23.0×
popupMatchSelectWidthDetermine whether the popup menu and the select input are the same width. Default set min-width same as input. Will ignore when value less than select width. false will disable virtual scrollboolean | numbertrue5.5.0×
dropdownRenderCustomize dropdown content, use popupRender instead(originNode: ReactElement) => ReactNode-×
popupRenderCustomize dropdown content(originNode: ReactElement) => ReactNode-5.25.0×
dropdownStyleThe style of dropdown menu, use styles.popup.root insteadCSSProperties-×
fieldNamesCustomize node label, value, options,groupLabel field nameobject{ label: label, value: value, options: options, groupLabel: label }4.17.0 (groupLabel added in 5.6.0)×
filterOptionIf true, filter options by input, if function, filter options against it. The 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 excludedboolean | function(inputValue, option)true×
filterSortSort function for search options sorting, see Array.sort's compareFunction(optionA: Option, optionB: Option, info: { searchValue: string }) => number-searchValue: 5.19.0×
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×
labelInValueWhether to embed label in value, turn the format of value from string to { value: string, label: ReactNode }booleanfalse×
listHeightConfig popup heightnumber256×
loadingIndicate loading statebooleanfalse×
loadingIconCustomize the loading iconReactNode<LoadingOutlined spin />6.4.06.4.0
maxCountThe max number of items can be selected, only applies when mode is multiple or tagsnumber-5.13.0×
maxTagCountMax tag count to show. responsive will cost render performancenumber | responsive-responsive: 4.10×
maxTagPlaceholderPlaceholder for not showing tagsReactNode | function(omittedValues)-×
maxTagTextLengthMax tag text length to shownumber-×
menuItemSelectedIconThe custom menuItemSelected icon with multiple optionsReactNode<CheckOutlined />6.4.0
modeSet mode of Selectmultiple | tags-×
notFoundContentSpecify content to show when no result matchesReactNodeNo data×
openControlled open state of dropdownboolean-×
optionFilterPropDeprecated, see showSearch.optionFilterProp×
optionLabelPropWhich prop value of option will render as content of select. Examplestringchildren×
optionsSelect options. Will get better perf than jsx definition{ label, value }[]-×
optionRenderCustomize the rendering dropdown options(option: FlattenOptionData<BaseOptionType> , info: { index: number }) => React.ReactNode-5.11.0×
placeholderPlaceholder of selectReactNode-×
placementThe position where the selection box pops upbottomLeft bottomRight topLeft topRightbottomLeft×
prefixThe custom prefixReactNode-5.22.0×
removeIconThe custom remove iconReactNode<CloseOutlined />6.4.0
searchValueThe current input "search" textstring-×
showArrowWhether to show the arrow icon, please use suffixIcon={null} insteadbooleantrue-×
showSearchWhether select is searchableboolean | Objectsingle: false, multiple: trueObject: 6.0.06.4.0
sizeSize of Select inputlarge | medium | smallmedium×
statusSet validation status'error' | 'warning'-4.19.0×
stylesCustomize inline style for each semantic structure inside the Select component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-5.25.0
suffixIconThe custom suffix icon. Custom icons will not respond to clicks to open, because the replaced icon may be designed for other interactions. You can use pointer-events: none style to bypassReactNode<DownOutlined />6.4.0
tagRenderCustomize tag render, only applies when mode is set to multiple or tags(props) => ReactNode-×
labelRenderCustomize selected label render (LabelInValueType definition see LabelInValueType)(props: LabelInValueType) => ReactNode-5.15.0×
tokenSeparatorsSeparator used to tokenize, only applies when mode="tags" or mode="multiple"string[] | ((input: string) => string[])-function: 6.5.0×
valueCurrent selected option (considered as a immutable array)string | string[] | <br />number | number[] | <br />LabeledValue | LabeledValue[]-×
variantVariants of selectoroutlined | borderless | filled | underlinedoutlined5.13.0 | underlined: 5.24.05.19.0
virtualDisable virtual scroll when set to falsebooleantrue4.1.0×
onActiveCalled when keyboard or mouse interaction occursfunction(value: string | number | LabeledValue)-×
onBlurCalled when blurfunction-×
onChangeCalled when select an option or input value changefunction(value, option:Option | Array<Option>)-×
onClearCalled when clearfunction-4.6.0×
onDeselectCalled when an option is deselected, param is the selected option's value. Only called for multiple or tags, effective in multiple or tags mode onlyfunction(value: string | number | LabeledValue)-×
onDropdownVisibleChangeCalled when dropdown open, use onOpenChange instead(open: boolean) => void-×
onOpenChangeCalled when dropdown open(open: boolean) => void-×
onFocusCalled when focus(event: FocusEvent) => void-×
onInputKeyDownCalled when key pressed(event: KeyboardEvent) => void-×
onPopupScrollCalled when dropdown scrolls(event: UIEvent) => void-×
onSearchCallback function that is fired when input changedfunction(value: string)-×
onSelectCalled when an option is selected, the params are option's value (or key) and option instancefunction(value: string | number | LabeledValue, option: Option)-×

Note, if you find that the drop-down menu scrolls with the page, or you need to trigger Select in other popup layers, please try to use getPopupContainer={triggerNode => triggerNode.parentElement} to fix the drop-down popup rendering node in the parent element of the trigger .

showSearch

PropertyDescriptionTypeDefaultVersion
autoClearSearchValueWhether the current search will be cleared on selecting an item. Only applies when mode is set to multiple or tagsbooleantrue
filterOptionIf true, filter options by input, if function, filter options against it. The 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 excludedboolean | function(inputValue, option)true
filterSortSort function for search options sorting, see Array.sort's compareFunction(optionA: Option, optionB: Option, info: { searchValue: string }) => number-searchValue: 5.19.0
optionFilterPropWhich prop value of option will be used for filter if filterOption is true. <br/> If options is set, it should be set to label. <br/> When a string[] is provided, multiple fields are searched using OR matching.string | string[]valuestring[]: 6.1.0
searchValueThe current input "search" textstring-
onSearchCallback function that is fired when input changedfunction(value: string)-
searchIconCustomize the search iconReactNode<SearchOutlined />6.4.0

Select Methods

NameDescriptionVersion
blur()Remove focus
focus()Get focus

Option props

PropertyDescriptionTypeDefaultVersion
classNameThe additional class to optionstring-
disabledDisable this optionbooleanfalse
titletitle attribute of Select Optionstring-
valueDefault to filter with this propertystring | number-

OptGroup props

PropertyDescriptionTypeDefaultVersion
keyGroup keystring-
labelGroup labelReact.ReactNode-
classNameThe additional class to optionstring-
titletitle attribute of Select Optionstring-

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
zIndexPopupnumberz-index of dropdown
optionSelectedColorstringText color when option is selected
optionSelectedFontWeightCSSProperties['fontWeight']Font weight when option is selected
optionSelectedBgstringBackground color when option is selected
optionActiveBgstringBackground color when option is active
optionPaddingCSSProperties['padding']Padding of option
optionFontSizenumberFont size of option
optionLineHeightCSSProperties['lineHeight']Line height of option
optionHeightnumberHeight of option
selectorBgstringBackground color of selector
clearBgstringBackground color of clear button
singleItemHeightLGnumberHeight of single selected item with large size
showArrowPaddingInlineEndnumberInline end padding of arrow
hoverBorderColorstringHover border color
activeBorderColorstringActive border color
activeOutlineColorstringActive outline color

Declaration source: vendor/components/select/style/token.ts

import type { CSSProperties } from 'react';

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

export interface MultipleSelectorToken {
  /**
   * @desc 多选标签背景色
   * @descEN Background color of multiple tag
   */
  multipleItemBg: string;
  /**
   * @desc 多选标签边框色
   * @descEN Border color of multiple tag
   */
  multipleItemBorderColor: string;
  /**
   * @desc 多选标签高度
   * @descEN Height of multiple tag
   */
  multipleItemHeight: number;
  /**
   * @desc 小号多选标签高度
   * @descEN Height of multiple tag with small size
   */
  multipleItemHeightSM: number;
  /**
   * @desc 大号多选标签高度
   * @descEN Height of multiple tag with large size
   */
  multipleItemHeightLG: number;
  /**
   * @desc 多选框禁用背景
   * @descEN Background color of multiple selector when disabled
   */
  multipleSelectorBgDisabled: string;
  /**
   * @desc 多选标签禁用文本颜色
   * @descEN Text color of multiple tag when disabled
   */
  multipleItemColorDisabled: string;
  /**
   * @desc 多选标签禁用边框色
   * @descEN Border color of multiple tag when disabled
   */
  multipleItemBorderColorDisabled: string;
  /**
   * @internal
   */
}

export interface ComponentToken extends MultipleSelectorToken {
  /**
   * @desc 下拉菜单 z-index
   * @descEN z-index of dropdown
   */
  zIndexPopup: number;
  /**
   * @desc 选项选中时文本颜色
   * @descEN Text color when option is selected
   */
  optionSelectedColor: string;
  /**
   * @desc 选项选中时文本字重
   * @descEN Font weight when option is selected
   */
  optionSelectedFontWeight: CSSProperties['fontWeight'];
  /**
   * @desc 选项选中时背景色
   * @descEN Background color when option is selected
   */
  optionSelectedBg: string;
  /**
   * @desc 选项激活态时背景色
   * @descEN Background color when option is active
   */
  optionActiveBg: string;
  /**
   * @desc 选项内间距
   * @descEN Padding of option
   */
  optionPadding: CSSProperties['padding'];
  /**
   * @desc 选项字体大小
   * @descEN Font size of option
   */
  optionFontSize: number;
  /**
   * @desc 选项行高
   * @descEN Line height of option
   */
  optionLineHeight: CSSProperties['lineHeight'];
  /**
   * @desc 选项高度
   * @descEN Height of option
   */
  optionHeight: number;
  /**
   * @desc 选框背景色
   * @descEN Background color of selector
   */
  selectorBg: string;
  /**
   * @desc 清空按钮背景色
   * @descEN Background color of clear button
   */
  clearBg: string;
  /**
   * @desc 单选大号回填项高度
   * @descEN Height of single selected item with large size
   */
  singleItemHeightLG: number;
  /**
   * @desc 箭头的行末内边距
   * @descEN Inline end padding of arrow
   */
  showArrowPaddingInlineEnd: number;
  /**
   * @desc 悬浮态边框色
   * @descEN Hover border color
   */
  hoverBorderColor: string;
  /**
   * @desc 激活态边框色
   * @descEN Active border color
   */
  activeBorderColor: string;
  /**
   * @desc 激活态 outline 颜色
   * @descEN Active outline color
   */
  activeOutlineColor: string;
}

export interface SelectorToken {
  selectAffixPadding: number | string;
  inputPaddingHorizontalBase: number | string;
  multipleSelectItemHeight: number;
  selectHeight: number;
}

export interface SelectToken extends FullToken<'Select'>, SelectorToken {
  rootPrefixCls: string;

  /** @private Used for internal calculation */
  INTERNAL_FIXED_ITEM_MARGIN: number;
}

FAQ

Why sometimes search will show 2 same option when in tags mode?

It's caused by option with different label and value. You can use optionFilterProp="label" to change filter logic instead.

When I click elements in popupRender, the select dropdown will not be closed?

You can control it by open prop: codesandbox.

I don't want dropdown close when click inside popupRender?

Select will close when it lose focus. You can prevent event to handle this:

<Select
  popupRender={() => (
    <div
      onMouseDown={(e) => {
        e.preventDefault();
        e.stopPropagation();
      }}
    >
      Some Content
    </div>
  )}
/>

Why sometimes customize Option cause scroll break?

Virtual scroll internal set item height as 24px. You need to adjust listItemHeight when your option height is less and listHeight config list container height:

<Select listItemHeight={10} listHeight={250} />

Note: listItemHeight and listHeight are internal props. Please only modify when necessary.

Why a11y test report missing aria- props?

Select only create a11y auxiliary node when operating on. Please open Select and retry. For aria-label & aria-labelledby miss warning, please add related prop to Select with your own requirement.

Default virtual scrolling will create a mock element to simulate an accessible binding. If a screen reader needs to fully access the entire list, you can set virtual={false} to disable virtual scrolling and the accessibility option will be bound to the actual element.

Why does clicking close on a custom tagRender tag open the dropdown?

If you don't want a drop-down menu to appear automatically after clicking on an element (such as a close icon), you can prevent the MouseDown event from propagating on it.

<Select
  tagRender={(props) => {
    const { closable, label, onClose } = props;
    return (
      <span className="border">
        {label}
        {closable ? (
          <span
            onMouseDown={(e) => e.stopPropagation()}
            onClick={onClose}
            className="cursor-pointer"
          >
            ❎
          </span>
        ) : null}
      </span>
    );
  }}
/>

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/select/index.tsx
  • vendor/components/select/style/select-input.ts
  • vendor/components/select/style/token.ts
  • vendor/components/select/useIcons.tsx
  • vendor/components/select/usePopupRender.tsx

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.