Select
A dropdown menu for displaying choices.
When to use
- A dropdown menu for displaying choices - an elegant alternative to the native the native
selectelement 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
Width and long options
Long options — a job, a vendor, a stock location path — used to be cut off in a field narrower than the
space it had. The CeeBee Select sets three defaults on Ant's contract:
- The field is as wide as its longest option, between 12rem and 28rem, measured from the labels in
chso the server and the client agree. It never outgrows its container, so it takes the full width on a phone. Setstyle={{ width }}and your width is kept. - The dropdown may be wider than the field, up to 32rem (
popupMatchSelectWidthdefaults tofalse), so options are read whole where there is room. - What still does not fit ellipsises, and the selected value and each option show their whole text
in a tooltip when, and only when, they are cut. The full text stays the element's content, so the
accessible name is never the shortened one. A consumer's own
labelRenderoroptionRenderreplaces this for what it renders.
Clear action
When allowClear is enabled, the clear button uses the clear label from LabelsProvider; without a
provider override it keeps the default “Clear” label. The Ant Design clear icon also stays intact. A
caller-provided allowClear.label takes precedence over the provider label, and an explicit
allowClear.clearIcon takes precedence over configured icons. Without that icon, the Select clearIcon
prop, ConfigProvider's select.clearIcon, then Ant Design's default icon are used in that order.
The clear action has a token-sized hit area around its compact icon. It remains visible when reached by keyboard focus, with the shared focus indicator, even while the pointer is outside the Select.
Wrap the part of the app that needs localized library labels with LabelsProvider:
import { LabelsProvider, Select } from '@ceebee/ui/client';
<LabelsProvider labels={{ clear: 'Clear choice' }}> <Select allowClear options={[{ value: 'a', label: 'First choice' }]} value="a" /></LabelsProvider>An explicit label and icon stay with the Select:
<Select allowClear={{ label: 'Remove choice', clearIcon: <span aria-hidden="true">×</span> }} options={[{ value: 'a', label: 'First choice' }]} value="a"/>allowClear={false} disables clearing even when a ConfigProvider enables it. Omitting allowClear
keeps Ant Design's configured behavior, including a provider-level select.allowClear setting.
Sizes
small, middle (the default), and large map to --cb-control-height-sm, --cb-control-height-md,
and --cb-control-height-lg. Each is max() of a preferred step (--cb-control-height-base-*) and
the active pointer floor, so a density scale can retune the ladder but never take a control under its
floor. On a coarse pointer — a touch screen — --cb-control-floor becomes
--cb-control-floor-coarse (2.75rem, 44px), so small and middle both reach 44px and large keeps
its 48px, with no per-control CSS. A pointer that hovers keeps --cb-control-floor-fine (2rem, 32px).
API
Select, Select.Option, and Select.OptGroup are exported from @ceebee/ui/client.
Select props
| Property | Description | Type | Default | Version |
|---|---|---|---|---|
allowClear | Customize clear icon | boolean | { clearIcon?: ReactNode } | false | 5.8.0: Support object type |
autoClearSearchValue | Whether the current search will be cleared on selecting an item. Only applies when mode is set to multiple or tags | boolean | true | — |
bordered | Whether has border style, please use variant instead | boolean | true | - |
classNames | Customize class for each semantic structure inside the Select component. Supports object or function. | Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string> | - | — |
defaultActiveFirstOption | Whether active first option by default | boolean | true | — |
defaultOpen | Initial open state of dropdown | boolean | - | — |
defaultValue | Initial selected option | string | string\[] | <br />number | number\[] | <br />LabeledValue | LabeledValue\[] | - | — |
disabled | Whether disabled select | boolean | false | — |
dropdownClassName | The className of dropdown menu, please use classNames.popup.root instead | string | - | - |
dropdownMatchSelectWidth | Determine whether the popup menu and the select input are the same width, please use popupMatchSelectWidth instead | boolean | number | true | - |
popupClassName | The className of dropdown menu, use classNames.popup.root instead | string | - | 4.23.0 |
popupMatchSelectWidth | Determine 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 scroll | boolean | number | true | 5.5.0 |
dropdownRender | Customize dropdown content, use popupRender instead | (originNode: ReactNode) => ReactNode | - | — |
popupRender | Customize dropdown content | (originNode: ReactNode) => ReactNode | - | 5.25.0 |
dropdownStyle | The style of dropdown menu, use styles.popup.root instead | CSSProperties | - | — |
fieldNames | Customize node label, value, options, groupLabel field name | object | { label: label, value: value, options: options, groupLabel: label } | 4.17.0 (groupLabel added in 5.6.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, info: { searchValue: string }) => number | - | searchValue: 5.19.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 | — |
loadingIcon | Customize the loading icon | ReactNode | <LoadingOutlined spin /> | 6.4.0 |
maxCount | The max number of items can be selected, only applies when mode is multiple or tags | number | - | 5.13.0 |
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 | <CheckOutlined /> | — |
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 | Deprecated, see showSearch.optionFilterProp | — | — | — |
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 }\[] | - | — |
optionRender | Customize the rendering dropdown options | (option: FlattenOptionData\<BaseOptionType\> , info: { index: number }) => React.ReactNode | - | 5.11.0 |
placeholder | Placeholder of select | ReactNode | - | — |
placement | The position where the selection box pops up | bottomLeft bottomRight topLeft topRight | bottomLeft | — |
prefix | The custom prefix | ReactNode | - | 5.22.0 |
removeIcon | The custom remove icon | ReactNode | <CloseOutlined /> | — |
searchValue | The current input "search" text | string | - | — |
showArrow | Whether to show the arrow icon, please use suffixIcon={null} instead | boolean | true | - |
showSearch | Whether select is searchable | boolean | Object | single: false, multiple: true | Object: 6.0.0 |
size | Size of Select input | large | medium | small | medium | — |
status | Set validation status | 'error' | 'warning' | - | 4.19.0 |
styles | Customize inline style for each semantic structure inside the Select component. Supports object or function. | Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties> | - | — |
suffixIcon | The 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 bypass | ReactNode | <DownOutlined /> | — |
tagRender | Customize tag render, only applies when mode is set to multiple or tags | (props) => ReactNode | - | — |
labelRender | Customize selected label render (LabelInValueType definition see LabelInValueType) | (props: LabelInValueType) => ReactNode | - | 5.15.0 |
tokenSeparators | Separator used to tokenize, only applies when mode="tags" or mode="multiple" | string[] | ((input: string) => string[]) | - | function: 6.5.0 |
value | Current selected option (considered as a immutable array) | string | string\[] | <br />number | number\[] | <br />LabeledValue | LabeledValue\[] | - | — |
variant | Variants of selector | outlined | borderless | filled | underlined | outlined | 5.13.0 | underlined: 5.24.0 |
virtual | Disable virtual scroll when set to false | boolean | true | 4.1.0 |
onActive | Called when keyboard or mouse interaction occurs | function(value: string | number | LabeledValue) | - | — |
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(value: string | number | LabeledValue) | - | — |
onDropdownVisibleChange | Called when dropdown open, use onOpenChange instead | (open: boolean) => void | - | — |
onOpenChange | Called when dropdown open | (open: boolean) => void | - | — |
onFocus | Called when focus | (event: FocusEvent) => void | - | — |
onInputKeyDown | Called when key pressed | (event: KeyboardEvent) => void | - | — |
onPopupScroll | Called when dropdown scrolls | (event: UIEvent) => void | - | — |
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(value: string | number | LabeledValue, option: Option) | - | — |
showSearch
| Property | Description | Type | Default | Version |
|---|---|---|---|---|
autoClearSearchValue | Whether the current search will be cleared on selecting an item. Only applies when mode is set to multiple or tags | boolean | true | — |
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, info: { searchValue: string }) => number | - | searchValue: 5.19.0 |
optionFilterProp | Which 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[] | value | string[]: 6.1.0 |
searchValue | The current input "search" text | string | - | — |
onSearch | Callback function that is fired when input changed | function(value: string) | - | — |
searchIcon | Customize the search icon | ReactNode | <SearchOutlined /> | 6.4.0 |
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 | React.ReactNode | - | — |
className | The additional class to option | string | - | — |
title | title attribute of Select Option | string | - | — |