Multi select
MultiSelect is a dropdown for choosing several options. The selected options show as chips in the field. Use Select when only one option can be chosen.
Example
Props
Prop | Type | Default value | Description |
|---|---|---|---|
Prop value | Type string[] | Default value undefined | Description The selected values, for a controlled field |
Prop defaultValue | Type string[] | Default value undefined | Description The initially selected values, for an uncontrolled field |
Prop onSelect | Type (value: string[], type?, evt?) => void | Default value undefined | Description Called with the new array of selected values |
Prop options | Type SelectOptionListItem[] | Default value undefined | Description The options, as an alternative to MultiSelect.Item children |
Prop children | Type ReactNode | Default value undefined | Description MultiSelect.Item and MultiSelect.Group elements, as an alternative to options |
Prop label | Type ReactNode | Default value undefined | Description Label shown with the field |
Prop placeholder | Type string | Default value undefined | Description Text shown when nothing is selected |
Prop error | Type ReactNode | Default value undefined | Description Pass true for the error style, or a message to show below the field |
Prop disabled | Type boolean | Default value undefined | Description Whether the field is disabled |
Prop sortable | Type boolean | Default value undefined | Description Whether the selected chips can be reordered by dragging |
Prop showSearch | Type boolean | Default value undefined | Description Whether to show a search input in the dropdown |
Prop allowCreateOption | Type boolean | Default value undefined | Description Whether people can add an option that is not in the list |
Prop maxHeight | Type string | Default value undefined | Description Maximum height of the dropdown |
Prop orientation | Type "vertical" | "horizontal" | Default value undefined | Description Whether the label sits above or beside the field |
Prop dir | Type "start" | "end" | Default value undefined | Description Which side of the field the label sits on |
Prop defaultOpen | Type boolean | Default value undefined | Description Whether the dropdown starts open |
Prop onOpenChange | Type (open: boolean) => void | Default value undefined | Description Called when the dropdown opens or closes |
Prop name | Type string | Default value undefined | Description Name submitted with a form |
Prop form | Type string | Default value undefined | Description ID of the form the field belongs to |
Prop container | Type HTMLElement | Default value undefined | Description Element the dropdown is portalled into |
MultiSelect.Item props
Prop | Type | Default value | Description |
|---|---|---|---|
Prop value * | Type string | Default value required | Description The value of the option |
Prop label * | Type ReactNode | Default value required | Description The text of the option |
Prop description | Type ReactNode | Default value undefined | Description Secondary text shown with the option |
Prop icon | Type IconName | LogoName | Default value undefined | Description Icon shown with the option |
Prop iconDir | Type "start" | "end" | Default value undefined | Description Which side of the label the icon sits on |
Prop disabled | Type boolean | Default value undefined | Description Whether the option can be chosen |
Prop separator | Type boolean | Default value undefined | Description Whether to draw a separator after the option |
* denotes required field
MultiSelect.Group takes a required heading and wraps the items in that group.
Quick start
import { MultiSelect } from '@clickhouse/click-ui'
import { useState } from 'react'
function Regions() {
const [regions, setRegions] = useState<string[]>([])
return (
<MultiSelect label='Regions' value={regions} onSelect={setRegions}>
<MultiSelect.Group heading='Europe'>
<MultiSelect.Item value='eu-west' label='EU West' />
<MultiSelect.Item value='eu-central' label='EU Central' />
</MultiSelect.Group>
<MultiSelect.Group heading='Americas'>
<MultiSelect.Item value='us-east' label='US East' />
</MultiSelect.Group>
</MultiSelect>
)
}Related components
- Select: For choosing a single option.
- CheckboxMultiSelect: For a dropdown of checkboxes instead of chips.
- AutoComplete: For a text input that suggests options.
Common use cases
Grouped options
Error state
Choose at least one tag