MultiSelect
Custom searchable multi select
Import
Source
Docs
Package
Made with Combobox
MultiSelect
is an opinionated component built on top of Combobox component. It has a limited set of features to cover only the basic use cases. If you need more advanced features, you can build your own component with Combobox. You can find examples of custom multi select components on the examples page.
Usage
MultiSelect
provides a way to enter multiple values.
MultiSelect
is similar to TagsInput, but it does not allow entering custom values.
Controlled
MultiSelect
value must be an array of strings, other types are not supported.
onChange
function is called with an array of strings as a single argument.
Searchable
Set searchable
prop to allow filtering options by user input:
Nothing found
Set nothingFoundMessage
prop to display given message when no options match search query.
If nothingFoundMessage
is not set, MultiSelect
dropdown will be hidden when no options match search query.
The message is not displayed when trimmed search query is empty.
Checked option icon
Set checkIconPosition
prop to left
or right
to control position of check icon in active option.
To remove the check icon, set withCheckIcon={false}
.
Max selected values
You can limit the number of selected values with maxValues
prop. This will not allow adding more values
once the limit is reached.
Hide selected options
To remove selected options from the list of available options, set hidePickedOptions
prop:
Data formats
MultiSelect
data
prop accepts data in one of the following formats:
Array of strings:
Array of object with value
, label
and optional disabled
keys:
Array of groups with string options:
Array of groups with object options:
Options filtering
By default,MultiSelect
filters options by checking if the option label contains input value. You can change this behavior with filter
prop.filter
function receives an object with the following properties as a single argument:options
– array of options or options groups, all options are in{ value: string; label: string; disabled?: boolean }
formatsearch
– current search querylimit
– value oflimit
prop passed toMultiSelect
Example of a custom filter function that matches options by words instead of letters sequence:
Sort options
By default, options are sorted by their position in the data array. You can change this behavior
with filter
function:
Large data sets
The best strategy for large data sets is to limit the number of options that are rendered at the same time. You can do it with limit
prop. Note that if you use a custom filter
function, you need to implement your own logic to limit the number of options in filter
Example of MultiSelect
with 100 000 options, 5 options are rendered at the same time:
Scrollable dropdown
By default, the options list is wrapped with ScrollArea.Autosize.
You can control dropdown max-height with maxDropdownHeight
prop if you do not change the default settings.
If you want to use native scrollbars, set withScrollArea={false}
. Note that in this case,
you will need to change dropdown styles with Styles API.
Group options
Disabled options
When option is disabled, it cannot be selected and is ignored in keyboard navigation.
Note that user can still enter disabled option as a value. If you want to prohibit certain values,
use controlled component and filter them out in onChange
function.
Combobox props
You can override Combobox props with comboboxProps
. It is useful when you need to change some of the props that are not exposed by MultiSelect
, for example withinPortal
:
Input props
MultiSelect
component supports Input and Input.Wrapper components features and all input
element props. MultiSelect
documentation does not include all features supported by the component – see Input documentation to learn about all available features.
Input description
Read only
Set readOnly
to make the input read only. When readOnly
is set,
MultiSelect
will not show suggestions and will not call onChange
function.
Disabled
Set disabled
to disable the input. When disabled
is set,
user cannot interact with the input and MultiSelect
will not show suggestions.
Error state
Invalid name
Styles API
MultiSelect
supports Styles API, you can add styles to any inner element of the component withclassNames
prop. Follow Styles API documentation to learn more.
Description
Component Styles API
Hover over selectors to highlight corresponding elements
Get element ref
Accessibility
If MultiSelect
is used without label
prop, it will not be announced properly by screen reader:
Set aria-label
to make the input accessible. In this case label will not be visible, but screen reader will announce it:
If label
prop is set, input will be accessible it is not required to set aria-label
: