* build: try to use dumi as doc tool * docs: migrate demo structure to dumi way * refactor: use type export & import * docs: migrate demo previewer to dumi * docs: create empty layout & components * docs: apply custom rehype plugin * docs: create empty extra pages * docs: Add Banner component * chore: move theme tsconfig.json * docs: home page init * docs: migrate header (#37896) * docs: header * docs: update * docs: home init * clean up * test: fix site lint * chore: tsc ignore demo * chore: dumi demo migrate script * chore: cards * docs: home layout * docs: Update locale logic * docs: fix getLink logic * chore: fix ci (#37899) * chore: fix ci * ci: remove check-ts-demo * ci: preview build * test: ignore demo.tsx * chore: update script * test: update snapshot * test: update node and image test * chore: add .surgeignore * docs: layout providers (#37908) * docs: add components sidebar (#37923) * docs: sidebar * docs: update docs title * docs: update design doc * chore: code clean * docs: handle changelog page * docs: add title * docs: add subtitle * docs: active header nav * chore: code clean * docs: overview * chore: code clean * docs: update intl (#37918) * docs: update intl * chore: code clean * docs: update favicons * chore: update testPathIgnorePatterns * chore: code clean * chore: code clean * chore: copy 404.html (#37996) * docs: Home page theme picker * chore: Update migrate script * docs: home page update * docs: theme editor style * docs: theme lang * chore: update migrate.js * docs: fix demo (#38094) * chore: update migrate.js * docs: update md * docs: update demo * test: fix snapshot * chore: move debug to code attr in migrate script * chore: update md Co-authored-by: PeachScript <scdzwyxst@gmail.com> * feat: overview page * feat: Migrate `404` page (#38118) * feat: migrate IconSearch component (#37916) * feat<site/IconSearch>: copy IconDisplay from site to .dumi * feat<site/IconSearch>: change docs of icon * feat<site/IconSearch>: tweak * feat<site/IconSearch>: use useIntl instead of injectIntl * feat<site/IconSearch>: fix ts type error * feat<site/IconSearch>: use intl.formatMessage to render text * docs: Adjust home btn sizw * docs: Update doc * feat: v5 site overview page (#38131) * feat: site * fix: fix * feat: v5 site overview page * fix: fix path * fix: fix * fix: fix * docs: fix margin logic * feat: v5 site change-log page (#38137) * feat: v5 site change-log page (#38162) * docs: site redirect to home pag * docs: theme picker * docs: use react-intl from dumi (#38183) * docs: Theme Picker * docs: update dumi config * docs: home back fix * docs: picker colorful * docs: locale of it * docs: update components desc * docs: site of links * docs: update components list * docs: update desc * feat: Migrate `DemoWrapper` component (#38166) * feat: Migrate `DemoWrapper` component * feat: remove invalid comments and add comment for `key` prop * docs: FloatButton pure panel * chore: update demo * chore: update dumi config * Revert "chore: update demo" This reverts commit 028265d3ba5987df5f13c3e9d42cf76cb1812b2e. * chore: test logic adjust to support cnpm modules * chore: add locale alias * docs: /index to / * docs: add locale redirect head script * chore: adjust compact * docs: fix missing token * feat: compact switch * chore: code clean * docs: update home * docs: fix radius token * docs: hash of it * chore: adjust home page * docs: Add background map * docs: site theme bac logic * docs: avatar * docs: update logo color * docs: home banner * docs: adjust tour size * docs: purepanl update * docs: transfooter * docs: update banner gif * docs: content (#38361) * docs: title & EditButton * docs: content * chore: fix toc * docs: resource page * docs: transform resource data from hast * docs: filename & Resource Card * chore: enable prerender * chore: remove less * docs: toc style * chore: fix lint * docs: fix Layout page * docs: fix CP page * chore: update demos * docs: workaround for export dynamic html * chore: enable demo eslint * docs: table style * fix: header shadow * chore: update snapshot * fix: toc style * docs: add title * docs: Adjust site * feat: helmet * docs: site css * fix: description * feat: toc debug * docs: update config-provider * feat: use colorPanel * fix: colorPanel value * feat: anchor ink ball style * feat: apply theme editor * fix: code block style * chore: update demo * chore: fix lint * chore: code clean * chore: update snapshot * feat: ts2js * chore: description * docs: site ready for ssr includes: - move client render logic to useEffect in site theme - extract antd cssinjs to a single css file like bisheng - workaround to support react@18 pipeableStream for emotion * chore: bump testing lib * docs: font size of title * chore: remove react-sortable-hoc * chore: update snapshot * chore: update script Co-authored-by: PeachScript <scdzwyxst@gmail.com> Co-authored-by: MadCcc <1075746765@qq.com> Co-authored-by: zqran <uuxnet@gmail.com> Co-authored-by: TrickyPi <530257315@qq.com> Co-authored-by: lijianan <574980606@qq.com>
29 KiB
category | group | title | cover | demo | ||
---|---|---|---|---|---|---|
Components | Data Entry | Select | https://gw.alipayobjects.com/zos/alicdn/_0XzgOis7/Select.svg |
|
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
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
Suffix
Custom dropdown
Hide Already Selected
Bordered-less
Custom Tag Render
Responsive maxTagCount
Big Data
Status
Placement
4.0 Debug
_InternalPanelDoNotUseOrYouWillBeFired
API
<Select>
<Option value="lucy">lucy</Option>
</Select>
Select props
Property | Description | Type | Default | Version |
---|---|---|---|---|
allowClear | Show clear button | boolean | false | |
autoClearSearchValue | Whether the current search will be cleared on selecting an item. Only applies when mode is set to multiple or tags |
boolean | true | |
autoFocus | Get focus by default | boolean | false | |
bordered | Whether has border style | boolean | true | |
clearIcon | The custom clear icon | ReactNode | - | |
defaultActiveFirstOption | Whether active first option by default | boolean | true | |
defaultOpen | Initial open state of dropdown | boolean | - | |
defaultValue | Initial selected option | string | string[] number | number[] LabeledValue | LabeledValue[] |
- | |
disabled | Whether disabled select | boolean | false | |
popupClassName | The className of dropdown menu | string | - | 4.23.0 |
dropdownMatchSelectWidth | Determine whether the dropdown 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 scroll |
boolean | number | true | |
dropdownRender | Customize dropdown content | (originNode: ReactNode) => ReactNode | - | |
dropdownStyle | The style of dropdown menu | CSSProperties | - | |
fieldNames | Customize node label, value, options field name | object | { label: label , value: value , options: options } |
4.17.0 |
filterOption | If 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 excluded |
boolean | function(inputValue, option) | true | |
filterSort | Sort function for search options sorting, see Array.sort's compareFunction | (optionA: Option, optionB: Option) => number | - | 4.9.0 |
getPopupContainer | Parent 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. Example |
function(triggerNode) | () => document.body | |
labelInValue | Whether to embed label in value, turn the format of value from string to { value: string, label: ReactNode } |
boolean | false | |
listHeight | Config popup height | number | 256 | |
loading | Indicate loading state | boolean | false | |
maxTagCount | Max tag count to show. responsive will cost render performance |
number | responsive |
- | responsive: 4.10 |
maxTagPlaceholder | Placeholder for not showing tags | ReactNode | function(omittedValues) | - | |
maxTagTextLength | Max tag text length to show | number | - | |
menuItemSelectedIcon | The custom menuItemSelected icon with multiple options | ReactNode | - | |
mode | Set mode of Select | multiple | tags |
- | |
notFoundContent | Specify content to show when no result matches | ReactNode | Not Found |
|
open | Controlled open state of dropdown | boolean | - | |
optionFilterProp | Which prop value of option will be used for filter if filterOption is true. If options is set, it should be set to label |
string | value |
|
optionLabelProp | Which prop value of option will render as content of select. Example | string | children |
|
options | Select options. Will get better perf than jsx definition | { label, value }[] | - | |
placeholder | Placeholder of select | ReactNode | - | |
placement | The position where the selection box pops up | bottomLeft bottomRight topLeft topRight |
bottomLeft | |
removeIcon | The custom remove icon | ReactNode | - | |
searchValue | The current input "search" text | string | - | |
showArrow | Whether to show the drop-down arrow | boolean | true(for single select), false(for multiple select) | |
showSearch | Whether select is searchable | boolean | single: false, multple: true | |
size | Size of Select input | large | middle | small |
middle |
|
status | Set validation status | 'error' | 'warning' | - | 4.19.0 |
suffixIcon | The custom suffix icon | ReactNode | - | |
tagRender | Customize tag render, only applies when mode is set to multiple or tags |
(props) => ReactNode | - | |
tokenSeparators | Separator used to tokenize, only applies when mode="tags" |
string[] | - | |
value | Current selected option (considered as a immutable array) | string | string[] number | number[] LabeledValue | LabeledValue[] |
- | |
virtual | Disable virtual scroll when set to false | boolean | true | 4.1.0 |
onBlur | Called when blur | function | - | |
onChange | Called when select an option or input value change | function(value, option:Option | Array<Option>) | - | |
onClear | Called when clear | function | - | 4.6.0 |
onDeselect | Called when an option is deselected, param is the selected option's value. Only called for multiple or tags , effective in multiple or tags mode only |
function(string | number | LabeledValue) | - | |
onDropdownVisibleChange | Called when dropdown open | function(open) | - | |
onFocus | Called when focus | function | - | |
onInputKeyDown | Called when key pressed | function | - | |
onMouseEnter | Called when mouse enter | function | - | |
onMouseLeave | Called when mouse leave | function | - | |
onPopupScroll | Called when dropdown scrolls | function | - | |
onSearch | Callback function that is fired when input changed | function(value: string) | - | |
onSelect | Called when an option is selected, the params are option's value (or key) and option instance | function(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
Name | Description | Version |
---|---|---|
blur() | Remove focus | |
focus() | Get focus |
Option props
Property | Description | Type | Default | Version |
---|---|---|---|---|
className | The additional class to option | string | - | |
disabled | Disable this option | boolean | false | |
title | title attribute of Select Option |
string | - | |
value | Default to filter with this property | string | number | - |
OptGroup props
Property | Description | Type | Default | Version |
---|---|---|---|---|
key | Group key | string | - | |
label | Group label | string | React.Element | - |
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.