Select
The select and search controls allow the user to select an option or options.
Select menus in Base hover atop of a selection menu while providing a simple list of options. Proper spacing, color, and a check-mark are clear indicators of a selection. Each menu is scrollable, if applicable.
Examples
Things to note in the example source code:
- the
valueis always anArrayto provide a consistent interface - no matter if you use multi or single selects, - you have to call
setStatewith the entire object, not just theidvalue.
When type is 'search' a magnifying glass icon will be rendered to the input's left and a dropdown arrow will not be rendered to the right.
The creatable select enables users to create new options along with choosing existing options.
Use startOpen to mount the Select with an open dropdown.
Combine this with autoFocus if you want the input to be focused as well.
Note, the dropdown will close once an item is selected or if the escape key is pressed while the Select has focus.
If you want the dropdown to stay open you might be better off using Menu directly.
To override the Popover that's being used by the Dropdown subcomponent, you have to use a nested override.
Overrides
Additionally, you can fully customize any part of the Select through the overrides prop. The Select consists of multiple subcomponents that are listed bellow and you can override each one of them. To help you identify the names of these subcomponents, you can highlight them through this selector:
Note: You should always use longhand CSS properties. Mixing shorthands and longhands will lead into strange behaviors!
API
Select API
"aria-label" nullable string = null
"aria-describedby" nullable string = null
"aria-labelledby" nullable string = null
autoFocus boolean = false
Defines if select element is focused on the first mount.
backspaceRemoves boolean = true
Defines if options can be removed by pressing backspace.
clearable boolean = true
Defines if the select value can be cleared. If true a clear icon is rendered when a value is set.
closeOnSelect boolean = true
Defines if the menu closes after a selection if made.
creatable boolean = false
Defines if new options can be created along with choosing existing options.
deleteRemoves boolean = true
Defines if options can be removed by pressing backspace.
disabled boolean = false
Defines if the control is disabled.
error boolean = false
Defines if the control is in error state.
positive boolean = false
Defines if the control if in positive state.
escapeClearsValue boolean = true
Defines if the value is cleared when escape is pressed and the dropdown is closed.
filterOptions nullable function = (options, filterValue, excludeOptions, newProps) => undefined
Defaults to filterOptions that excludes selected options for multi select. A custom method to filter options to be displayed in the dropdown.
function $ReadOnlyArray$ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean , string, $ReadOnlyArray$ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean , valueKey string required labelKey string required => $ReadOnlyArray$ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean filterOutSelected boolean = true
Defines if currently selected options are filtered out in the dropdown options.
getOptionLabel nullable function = null
A custom method to get a display value for a dropdown option.
option required $ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean optionState object required $selected boolean required $disabled boolean required $isHighlighted boolean required => NodegetValueLabel nullable function = null
A custom method to get a display value for a selected option.
option required $ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean => Nodeid string
Sets the id attribute of the internal input element. Allows for usage with labels.
isLoading boolean = false
Defines if the select if in a loading (async) state.
labelKey string = "label"
Defines an option key for a default label value.
maxDropdownHeight string = "900px"
Sets max height of the dropdown list.
multi boolean = false
Defines if multiple options can be selected.
noResultsMsg Node
Message to be displayed if no options is found for a search query.
NodeonBlur function = () => undefined
Event => mixedonBlurResetsInput boolean = true
Defines if the input value is reset to an empty string when a blur event happens on the select.
onChange function = () => undefined
change handler of the select to be called when a value is changed.
value required $ReadOnlyArray$ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean option nullable required $ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean type required $KeysObject.freeze({ select: "select", remove: "remove", clear: "clear" }) => mixedonFocus function = () => undefined
SyntheticEventHTMLElement => mixedonInputChange function = () => undefined
SyntheticInputEventHTMLInputElement => mixedonCloseResetsInput boolean = true
Defines if the input value is reset to an empty string when dropdown is closed.
onSelectResetsInput boolean = true
Defines if the input value is reset to an empty string when a selection is made.
onOpen nullable function = null
A function that is called when the dropdown opens.
() => mixedonClose nullable function = null
A function that is called when the dropdown closes.
() => mixedopenOnClick boolean = true
Defines if the dropdown opens on a click event on the select.
startOpen boolean = false
If true, opens the dropdown when the select mounts.
options nullable $ReadOnlyArray<$ReadOnly<object>> = []
Options to be displayed in the dropdown. If an option has a disabled prop value set to true it will be rendered as a disabled option in the dropdown.
$ReadOnlyArray$ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean overrides object = {}
Root { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*ControlContainer { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*Placeholder { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*ValueContainer { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*SingleValue { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*MultiValue { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*InputContainer { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*Input { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*IconsContainer { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*SelectArrow { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*ClearIcon { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*LoadingIndicator { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*SearchIcon { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*Popover { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*DropdownContainer { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*Dropdown { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*DropdownOption { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*DropdownListItem { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*OptionContent { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*StatefulMenu { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*placeholder Node
Sets the placeholder.
Noderequired boolean = false
Defines if the select field is required to have a selection.
searchable boolean = true
Defines if the search functionality is enabled.
size $Keys<typeof SIZE> =
Defines the size (scale) of dropdown menu items. See the Menu component API.
$Keys{ default: "default", compact: "compact", large: "large" }type $Keys<typeof TYPE> =
Defines type of the component to be in select or search mode. When set to TYPE.search the search icon if rendered on the left and the select arrow icon is not rendered.
$Keys{ select: "select", search: "search" }value $ReadOnlyArray<$ReadOnly<object>> = []
A current selected value(s). If a selected value has a clearableValue prop set to true it will be rendered as a disabled selected option that can't be cleared.
$ReadOnlyArray$ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean valueKey string = "id"
Defines a key name for an option's unique identifier value.
The value of the valueKey prop is used to identify what options are selected
or removed from the selection, it also used for default filtering out the
selected options from the dropdown list.
mountNode HTMLElement
Where to mount the popover
HTMLElementStatefulSelectContainer API
overrides object = {}
Root { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*ControlContainer { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*Placeholder { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*ValueContainer { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*SingleValue { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*MultiValue { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*InputContainer { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*Input { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*IconsContainer { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*SelectArrow { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*ClearIcon { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*LoadingIndicator { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*SearchIcon { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*Popover { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*DropdownContainer { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*Dropdown { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*DropdownOption { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*DropdownListItem { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*OptionContent { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*StatefulMenu { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*children function required
"aria-label" nullable required string"aria-describedby" nullable required string"aria-labelledby" nullable required stringautoFocus boolean required backspaceRemoves boolean required clearable boolean required closeOnSelect boolean required creatable boolean required deleteRemoves boolean required disabled boolean required error boolean required positive boolean required escapeClearsValue boolean required filterOptions nullable required function $ReadOnlyArray$ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean , string, $ReadOnlyArray$ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean , valueKey string required labelKey string required => $ReadOnlyArray$ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean filterOutSelected boolean required getOptionLabel nullable required option required $ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean optionState object required $selected boolean required $disabled boolean required $isHighlighted boolean required => NodegetValueLabel nullable required option required $ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean => Nodeid string isLoading boolean required labelKey string required maxDropdownHeight string required multi boolean required noResultsMsg NodeonBlur function required Event => mixedonBlurResetsInput boolean required onChange function required value required $ReadOnlyArray$ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean option nullable required $ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean type required $KeysObject.freeze({ select: "select", remove: "remove", clear: "clear" }) => mixedonFocus function required SyntheticEventHTMLElement => mixedonInputChange function required SyntheticInputEventHTMLInputElement => mixedonCloseResetsInput boolean required onSelectResetsInput boolean required onOpen nullable required () => mixedonClose nullable required () => mixedopenOnClick boolean required startOpen boolean required options nullable required $ReadOnlyArray$ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean overrides required Root { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*ControlContainer { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*Placeholder { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*ValueContainer { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*SingleValue { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*MultiValue { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*InputContainer { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*Input { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*IconsContainer { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*SelectArrow { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*ClearIcon { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*LoadingIndicator { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*SearchIcon { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*Popover { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*DropdownContainer { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*Dropdown { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*DropdownOption { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*DropdownListItem { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*OptionContent { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*StatefulMenu { component: ?ComponentType<<T> & { children: Node }>, props: ?{} | ({}) => ?{}, style: ?{} | ({}) => ?{} }<<T>> | ComponentType<<T> & { children: Node }>*placeholder Noderequired boolean required searchable boolean required size required $Keys{ default: "default", compact: "compact", large: "large" }type required $Keys{ select: "select", search: "search" }value required $ReadOnlyArray$ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean valueKey string required mountNode HTMLElement => React$NodeinitialState object = { value: [] }
value required $ReadOnlyArray$ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean stateReducer function = (type, nextState) => undefined
function string, value required $ReadOnlyArray$ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean , value required $ReadOnlyArray$ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean => value required $ReadOnlyArray$ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean onChange function = () => undefined
value required $ReadOnlyArray$ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean option nullable required $ReadOnlyid union One of string, numberlabel Nodedisabled boolean clearableValue boolean isCreatable boolean type required $KeysObject.freeze({ select: "select", remove: "remove", clear: "clear" }) => mixedSelect exports
You can import this module like so:
import {Select} from 'baseui/select'
It exports the following components or utility functions:
- Select
- SingleValue
- MultiValue
- AutosizeInput
- SelectDropdown
- StatefulSelect
- StatefulSelectContainer
- StyledRoot
- StyledControlContainer
- StyledValueContainer
- StyledPlaceholder
- StyledSingleValue
- StyledInputContainer
- StyledInput
- StyledInputSizer
- StyledIconsContainer
- StyledSelectArrow
- StyledClearIcon
- StyledSearchIcon
- StyledDropdownContainer
- StyledDropdown
- StyledDropdownListItem
- StyledOptionContent
- filterOptions
- SIZE
- TYPE
- STATE_CHANGE_TYPE