logoNamu Design

⌘ K
  • Design
  • Development
  • Components
  • Blog
  • Resources
1.0.0
  • Components Overview
  • General
    • Button
    • FloatButtonNew
    • Icon
    • Typography
  • Layout
    • Divider
    • Grid
    • Layout
    • Space
  • Navigation
    • Anchor
    • Breadcrumb
    • Dropdown
    • Menu
    • Pagination
    • Steps
  • Data Entry
    • AutoComplete
    • Cascader
    • Checkbox
    • ColorPickerNew
    • DatePicker
    • Form
    • Input
    • InputNumber
    • Mentions
    • Radio
    • Rate
    • Select
    • Slider
    • Switch
    • TimePicker
    • Transfer
    • TreeSelect
    • Upload
  • Data Display
    • Avatar
    • Badge
    • Calendar
    • Card
    • Carousel
    • Collapse
    • Descriptions
    • Empty
    • Image
    • List
    • Popover
    • QRCodeNew
    • Segmented
    • Statistic
    • Table
    • Tabs
    • Tag
    • Timeline
    • Tooltip
    • TourNew
    • Tree
  • Feedback
    • Alert
    • Drawer
    • Message
    • Modal
    • Notification
    • Popconfirm
    • Progress
    • Result
    • Skeleton
    • Spin
    • Watermark
  • Other
    • Affix
    • AppNew
    • ConfigProvider
When To Use
Examples
Basic Usage
Select with search field
multiple selection
Sizes
Custom selection render
Search with sort
Tags
Option Group
coordinate
Search Box
Get value of selected item
Automatic tokenization
Search and Select Users
Custom dropdown
Hide Already Selected
Bordered-less
Custom Tag Render
Responsive maxTagCount
Big Data
Status
Placement
API
Select props
Select Methods
Option props
OptGroup props
Design Token
FAQ
Why sometime search will show 2 same option when in tags mode?
When I click elements in dropdownRender, the select dropdown will not be closed?
I don't want dropdown close when click inside dropdownRender?
Why sometime customize Option cause scroll break?
Why a11y test report missing aria- props?

Select

  • RateSlider

    Resources

    Namu Design Charts
    Namu Design Pro
    Namu Design Pro Components
    Namu Design Mobile
    Namu Design Mini
    Namu Design Landing-Landing Templates
    Scaffolds-Scaffold Market
    Umi-React Application Framework
    dumi-Component doc generator
    qiankun-Micro-Frontends Framework
    ahooks-React Hooks Library
    Ant Motion-Motion Solution
    China Mirror 🇨🇳

    Community

    Awesome Namu Design
    Medium
    Twitter
    yuqueNamu Design in YuQue
    Namu Design in Zhihu
    Experience Cloud Blog
    seeconfSEE Conf-Experience Tech Conference

    Help

    GitHub
    Change Log
    FAQ
    Bug Report
    Issues
    Discussions
    StackOverflow
    SegmentFault

    Ant XTechMore Products

    yuqueYuQue-Document Collaboration Platform
    AntVAntV-Data Visualization
    EggEgg-Enterprise Node.js Framework
    kitchenKitchen-Sketch Toolkit
    xtechAnt Financial Experience Tech
    Theme Editor
    Made with ❤ by
    Ant Group and Namu Design Community

    Select component to select value from options.

    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).

    Examples

    Basic Usage

    Basic Usage.

    expand codeexpand code
    multiple selection

    Multiple selection, selecting from existing items.

    expand codeexpand code
    Custom selection render

    Specify the prop name of Option which will be rendered in select box.

    expand codeexpand code
    Tags

    Select with tags, transform input to tag (scroll the menu).

    expand codeexpand code
    coordinate

    Coordinating the selection of provinces and cities is a common use case and demonstrates how selection can be coordinated.

    Using the Cascader component is strongly recommended instead as it is more flexible and capable.

    expand codeexpand code
    Get value of selected item

    As a default behavior, the onChange callback can only get the value of the selected item. The labelInValue prop can be used to get the label property of the selected item.

    The label of the selected item will be packed as an object for passing to the onChange callback.

    expand codeexpand code
    Search and Select Users

    A complete multiple select sample with remote search, debounce fetch, ajax callback order flow, and loading state.

    expand codeexpand code
    Hide Already Selected

    Hide already selected options in the dropdown.

    expand codeexpand code
    Custom Tag Render

    Allows for custom rendering of tags.

    expand codeexpand code
    Big Data

    Select use virtual scroll which get better performance than 3.0.

    expand codeexpand code
    Placement

    You can manually specify the position of the popup via placement.

    expand codeexpand code
    Select with search field

    Search the options while expanded.

    expand codeexpand code
    Sizes

    The height of the input field for the select defaults to 32px. If size is set to large, the height will be 40px, and if set to small, 24px.

    expand codeexpand code
    Search with sort

    Search the options with sorting.

    expand codeexpand code
    Option Group

    Using OptGroup to group the options.

    expand codeexpand code
    Search Box

    Search with remote data.

    expand codeexpand code
    Automatic tokenization

    Try to copy Lucy,Jack and paste to the input. Only available in tags and multiple mode.

    expand codeexpand code
    Custom dropdown

    Customize the dropdown menu via dropdownRender. If you want to close the dropdown after clicking the custom content, you need to control open prop, here is an codesandbox.

    expand codeexpand code
    Bordered-less

    Bordered-less style component.

    expand codeexpand code
    Responsive maxTagCount

    Auto collapse to tag with responsive case. Not recommend use in large form case since responsive calculation has a perf cost.

    expand codeexpand code
    Status

    Add status to Select with status, which could be error or warning.

    expand codeexpand code

    API

    Common props ref:Common props

    Select props

    PropertyDescriptionTypeDefaultVersion
    allowClearShow clear buttonbooleanfalse
    autoClearSearchValueWhether the current search will be cleared on selecting an item. Only applies when mode is set to multiple or tagsbooleantrue
    autoFocusGet focus by defaultbooleanfalse
    borderedWhether has border stylebooleantrue
    clearIconThe custom clear iconReactNode-
    defaultActiveFirstOptionWhether active first option by defaultbooleantrue
    defaultOpenInitial open state of dropdownboolean-
    defaultValueInitial selected optionstring | string[] |
    number | number[] |
    LabeledValue | LabeledValue[]
    -
    disabledWhether disabled selectbooleanfalse
    popupClassNameThe className of dropdown menustring-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(originNode: ReactNode) => ReactNode-
    dropdownStyleThe style of dropdown menuCSSProperties-
    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) => number-4.9.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
    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-
    modeSet mode of Selectmultiple | tags-
    notFoundContentSpecify content to show when no result matchesReactNodeNot Found
    openControlled open state of dropdownboolean-
    optionFilterPropWhich prop value of option will be used for filter if filterOption is true. If options is set, it should be set to labelstringvalue
    optionLabelPropWhich prop value of option will render as content of select. Examplestringchildren
    optionsSelect options. Will get better perf than jsx definition{ label, value }[]-
    placeholderPlaceholder of selectReactNode-
    placementThe position where the selection box pops upbottomLeft bottomRight topLeft topRightbottomLeft
    removeIconThe custom remove iconReactNode-
    searchValueThe current input "search" textstring-
    showSearchWhether select is searchablebooleansingle: false, multiple: true
    sizeSize of Select inputlarge | middle | smallmiddle
    statusSet validation status'error' | 'warning'-4.19.0
    suffixIconThe custom suffix icon. Customize icon will not response click open to avoid icon designed to do other interactive. You can use pointer-events: none style to bypassReactNode<DownOutlined />
    tagRenderCustomize tag render, only applies when mode is set to multiple or tags(props) => ReactNode-
    tokenSeparatorsSeparator used to tokenize, only applies when mode="tags"string[]-
    valueCurrent selected option (considered as a immutable array)string | string[] |
    number | number[] |
    LabeledValue | LabeledValue[]
    -
    virtualDisable virtual scroll when set to falsebooleantrue4.1.0
    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 openfunction(open)-
    onFocusCalled when focusfunction-
    onInputKeyDownCalled when key pressedfunction-
    onMouseEnterCalled when mouse enterfunction-
    onMouseLeaveCalled when mouse leavefunction-
    onPopupScrollCalled when dropdown scrollsfunction-
    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 .

    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 labelstring | React.Element-

    Design Token

    Component Token

    Global Token

    FAQ

    Why sometime 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 dropdownRender, the select dropdown will not be closed?

    You can control it by open prop: codesandbox.

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

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

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

    Why sometime 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.

    Lucy
    Lucy
    Lucy
    Lucy
    a10
    c12
     
    a10
    c12
     
    China
     
     
    Tags Mode
    Zhejiang
    Hangzhou
    Lucy (101)
     
    Select users
     
    Inserted are removed
    gold
    cyan
     

    Namu Design 4.0

    100000 Items

    a10
    c12
     

    Namu Design 3.0



    HangZhou #310000
    Select a person


    a1
    a10
    c12
     
    a10
    c12
     
    Search to Select
    Lucy
    input search text
     
    custom dropdown render
    Lucy
    Lucy
    + 4 ...
     
    + 4 ...