2016-07-10 08:55:43 +08:00
---
category: Components
2016-11-09 14:43:32 +08:00
type: Data Entry
2016-07-10 08:55:43 +08:00
title: Select
---
2017-08-23 11:45:21 +08:00
Select component to select value from options.
2016-07-10 08:55:43 +08:00
2016-09-10 13:43:30 +08:00
## When To Use
2016-07-10 08:55:43 +08:00
2017-11-18 13:13:55 +08:00
- A dropdown menu for displaying choices - an elegant alternative to the native `<select>` element.
- Utilizing [Radio ](/components/radio/ ) is recommended when there are fewer total options (less than 5).
2016-10-14 11:29:45 +08:00
## API
2016-07-10 08:55:43 +08:00
```html
< Select >
< Option value = "lucy" > lucy< / Option >
< / Select >
```
### Select props
2017-10-25 10:25:44 +08:00
| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| allowClear | Show clear button. | boolean | false |
2018-09-30 15:04:03 +08:00
| autoClearSearchValue | Whether the current search will be cleared on selecting an item. Only applies when `mode` is set to `multiple` or `tags` . | boolean | true |
2017-11-11 00:07:03 +08:00
| autoFocus | Get focus by default | boolean | false |
2017-01-04 18:45:19 +08:00
| defaultActiveFirstOption | Whether active first option by default | boolean | true |
2018-07-21 15:00:20 +08:00
| defaultValue | Initial selected option. | string\|string\[]< br /> number\|number\[] | - |
2017-10-25 10:25:44 +08:00
| disabled | Whether disabled select | boolean | false |
2016-10-27 11:10:19 +08:00
| dropdownClassName | className of dropdown menu | string | - |
2018-06-15 10:16:37 +08:00
| dropdownMatchSelectWidth | Whether dropdown's width is same with select. | boolean | true |
2018-11-26 11:50:12 +08:00
| dropdownRender | Customize dropdown content | (menuNode: ReactNode, props) => ReactNode | - |
2017-10-25 10:25:44 +08:00
| dropdownStyle | style of dropdown menu | object | - |
| 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 or function(inputValue, option) | true |
| firstActiveValue | Value of action option by default | string\|string\[] | - |
2018-01-02 18:12:10 +08:00
| 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 ](https://codesandbox.io/s/4j168r7jw0 ) | function(triggerNode) | () => document.body |
2017-01-20 20:10:50 +08:00
| labelInValue | whether to embed label in value, turn the format of value from `string` to `{key: string, label: ReactNode}` | boolean | false |
2017-12-29 20:22:58 +08:00
| maxTagCount | Max tag count to show | number | - |
2017-11-28 09:51:29 +08:00
| maxTagPlaceholder | Placeholder for not showing tags | ReactNode/function(omittedValues) | - |
2018-09-12 21:43:01 +08:00
| mode | Set mode of Select | 'default' \| 'multiple' \| 'tags' | 'default' |
2017-10-25 10:25:44 +08:00
| notFoundContent | Specify content to show when no result matches.. | string | 'Not Found' |
| optionFilterProp | Which prop value of option will be used for filter if filterOption is true | string | value |
2018-03-24 21:37:28 +08:00
| optionLabelProp | Which prop value of option will render as content of select. | string | `value` for `combobox` , `children` for other modes |
2017-10-25 10:25:44 +08:00
| placeholder | Placeholder of select | string\|ReactNode | - |
2018-06-24 17:09:18 +08:00
| showArrow | Whether to show the drop-down arrow | boolean | true |
2017-10-25 10:25:44 +08:00
| showSearch | Whether show search input in single mode. | boolean | false |
| size | Size of Select input. `default` `large` `small` | string | default |
2018-09-16 19:43:53 +08:00
| suffixIcon | The custom suffix icon | ReactNode | - |
2018-12-02 01:42:22 +08:00
| removeIcon | The custom remove icon | ReactNode | - |
| clearIcon | The custom clear icon | ReactNode | - |
| menuItemSelectedIcon | The custom menuItemSelected icon | ReactNode | - |
2017-10-25 10:25:44 +08:00
| tokenSeparators | Separator used to tokenize on tag/multiple mode | string\[] | |
2018-01-08 14:26:48 +08:00
| value | Current selected option. | string\|number\|string\[]\|number\[] | - |
2017-10-25 10:25:44 +08:00
| onBlur | Called when blur | function | - |
2018-06-24 17:09:18 +08:00
| onChange | Called when select an option or input value change, or value of input is changed in combobox mode | function(value, option:Option/Array< Option>) | - |
2018-02-04 16:42:33 +08:00
| onDeselect | Called when a option is deselected, the params are option's value (or key) . only called for multiple or tags, effective in multiple or tags mode only. | function(value, option:Option) | - |
2017-10-25 10:25:44 +08:00
| onFocus | Called when focus | function | - |
2017-12-29 20:22:58 +08:00
| onInputKeyDown | Called when key pressed | function | - |
2017-11-11 00:07:03 +08:00
| onMouseEnter | Called when mouse enter | function | - |
| onMouseLeave | Called when mouse leave | function | - |
2017-11-19 20:14:53 +08:00
| onPopupScroll | Called when dropdown scrolls | function | - |
2017-10-25 10:25:44 +08:00
| onSearch | Callback function that is fired when input changed. | function(value: string) | |
2018-02-04 16:42:33 +08:00
| onSelect | Called when a option is selected, the params are option's value (or key) and option instance. | function(value, option:Option) | - |
2018-09-19 22:50:53 +08:00
| defaultOpen | Initial open state of dropdown | boolean | - |
| open | Controlled open state of dropdown | boolean | - |
2019-01-09 19:04:58 +08:00
| onDropdownVisibleChange | Call when dropdown open (Supported after version 3.9.0) | function(open) | - |
2018-11-27 12:01:30 +08:00
| loading | indicate loading state | Boolean | false |
2016-07-10 08:55:43 +08:00
2017-11-11 00:07:03 +08:00
### Select Methods
| Name | Description |
2017-12-29 20:22:58 +08:00
| ---- | ----------- |
2017-11-11 00:07:03 +08:00
| blur() | Remove focus |
| focus() | Get focus |
2016-07-10 08:55:43 +08:00
### Option props
2017-10-25 10:25:44 +08:00
| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| disabled | Disable this option | boolean | false |
| key | Same usage as `value` . If React request you to set this property, you can set it to value of option, and then omit value property. | string | |
2017-01-20 20:10:50 +08:00
| title | `title` of Select after select this Option | string | - |
2018-01-08 14:26:48 +08:00
| value | default to filter with this property | string\|number | - |
2018-10-02 04:28:18 +08:00
| className | additional class to option | string | - |
2016-07-10 08:55:43 +08:00
### OptGroup props
2017-10-25 10:25:44 +08:00
| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| key | | string | - |
| label | Group label | string\|React.Element | - |