# Combobox A flexible combobox component for both single and multi-selection, built for web applications with comprehensive accessibility support. ## Import ```tsx import { Combobox } from '@coinbase/cds-web/alpha/combobox' ``` ## Examples ### A note on search logic We use [fuse.js](https://www.fusejs.io/) to power the fuzzy search logic for Combobox. You can override this search logic with your own using the `filterFunction` prop. ### Multi-Select Basic multi-selection combobox with search. ```jsx live function MultiSelect() { const fruitOptions: SelectOption[] = [ { value: 'apple', label: 'Apple' }, { value: 'banana', label: 'Banana' }, { value: 'cherry', label: 'Cherry' }, { value: 'date', label: 'Date' }, { value: 'elderberry', label: 'Elderberry' }, { value: 'fig', label: 'Fig' }, { value: 'grape', label: 'Grape' }, { value: 'honeydew', label: 'Honeydew' }, { value: 'kiwi', label: 'Kiwi' }, { value: 'lemon', label: 'Lemon' }, { value: 'mango', label: 'Mango' }, { value: 'orange', label: 'Orange' }, { value: 'papaya', label: 'Papaya' }, { value: 'raspberry', label: 'Raspberry' }, { value: 'strawberry', label: 'Strawberry' }, ]; const { value, onChange } = useMultiSelect({ initialValue: ['apple', 'banana'] }); return ( ); } ``` ### Single Select Standard single-selection combobox with an option to clear the current value. ```jsx live function SingleSelect() { const singleSelectOptions = [ { value: null, label: 'Remove selection' }, { value: 'apple', label: 'Apple' }, { value: 'banana', label: 'Banana' }, { value: 'cherry', label: 'Cherry' }, { value: 'date', label: 'Date' }, ]; const [value, setValue] = useState('apple'); return ( ); } ``` ### Helper Text Communicate limits or guidance by pairing helper text with multi-select usage. ```jsx live function HelperText() { const fruitOptions: SelectOption[] = [ { value: 'apple', label: 'Apple' }, { value: 'banana', label: 'Banana' }, { value: 'cherry', label: 'Cherry' }, { value: 'date', label: 'Date' }, { value: 'elderberry', label: 'Elderberry' }, { value: 'fig', label: 'Fig' }, { value: 'grape', label: 'Grape' }, { value: 'honeydew', label: 'Honeydew' }, { value: 'kiwi', label: 'Kiwi' }, { value: 'lemon', label: 'Lemon' }, { value: 'mango', label: 'Mango' }, { value: 'orange', label: 'Orange' }, { value: 'papaya', label: 'Papaya' }, { value: 'raspberry', label: 'Raspberry' }, { value: 'strawberry', label: 'Strawberry' }, ]; const { value, onChange } = useMultiSelect({ initialValue: ['apple', 'banana'] }); return ( ); } ``` ## Props | Prop | Type | Required | Default | Description | | --- | --- | --- | --- | --- | | `onChange` | `(value: Type extends multi ? SelectOptionValue \| SelectOptionValue[] \| null : SelectOptionValue \| null) => void` | Yes | `-` | - | | `options` | `SelectOptionList` | Yes | `-` | Array of options to display in the select dropdown. Can be individual options or groups with label and options | | `value` | `string \| SelectOptionValue[] \| null` | Yes | `-` | - | | `ComboboxControlComponent` | `ComboboxControlComponent` | No | `-` | Custom ComboboxControlComponent to wrap SelectControlComponent. This component must be a stable reference | | `SelectAllOptionComponent` | `SelectOptionComponent` | No | `-` | Custom component to render the Select All option | | `SelectControlComponent` | `SelectControlComponent` | No | `-` | Custom component to render the select control | | `SelectDropdownComponent` | `SelectDropdownComponent` | No | `-` | Custom component to render the dropdown container | | `SelectEmptyDropdownContentsComponent` | `SelectEmptyDropdownContentComponent` | No | `-` | Custom component to render when no options are available | | `SelectOptionComponent` | `SelectOptionComponent` | No | `-` | Custom component to render individual options | | `SelectOptionGroupComponent` | `SelectOptionGroupComponent` | No | `-` | Custom component to render group headers | | `accessibilityRoles` | `{ dropdown?: AriaHasPopupType; option?: string \| undefined; } \| undefined` | No | `-` | Accessibility roles for dropdown and option elements | | `accessory` | `ReactElement>` | No | `-` | Accessory element rendered at the end of the cell (e.g., chevron). | | `className` | `string` | No | `-` | CSS class name for the root element | | `classNames` | `{ root?: string; control?: string \| undefined; controlStartNode?: string \| undefined; controlInputNode?: string \| undefined; controlValueNode?: string \| undefined; controlLabelNode?: string \| undefined; controlHelperTextNode?: string \| undefined; controlEndNode?: string \| undefined; dropdown?: string \| undefined; option?: string \| undefined; optionCell?: string \| undefined; optionContent?: string \| undefined; optionLabel?: string \| undefined; optionDescription?: string \| undefined; selectAllDivider?: string \| undefined; emptyContentsContainer?: string \| undefined; emptyContentsText?: string \| undefined; optionGroup?: string \| undefined; } \| undefined` | No | `-` | Custom class names for different parts of the select | | `clearAllLabel` | `string` | No | `-` | Label for the Clear All option in multi-select mode | | `compact` | `boolean` | No | `-` | Whether to use compact styling for the select | | `controlAccessibilityLabel` | `string` | No | `-` | Accessibility label for the control | | `defaultOpen` | `boolean` | No | `-` | Initial open state when component mounts (uncontrolled mode) | | `defaultSearchText` | `string` | No | `-` | Default search text value for uncontrolled mode | | `disableClickOutsideClose` | `boolean` | No | `-` | Whether clicking outside the dropdown should close it | | `disabled` | `boolean` | No | `false` | Toggles input interactability and opacity | | `emptyOptionsLabel` | `string` | No | `-` | Label displayed when there are no options available | | `end` | `null \| string \| number \| false \| true \| ReactElement> \| Iterable \| ReactPortal` | No | `-` | End-aligned content (e.g., value, status). Replaces the deprecated detail prop. | | `endNode` | `null \| string \| number \| false \| true \| ReactElement> \| Iterable \| ReactPortal` | No | `-` | Adds content to the end of the inner input. Refer to diagram for location of endNode in InputStack component | | `filterFunction` | `((options: SelectOptionList, searchText: string) => SelectOption[])` | No | `-` | Custom filter function for searching options | | `helperText` | `null \| string \| number \| false \| true \| ReactElement> \| Iterable \| ReactPortal` | No | `-` | Helper text displayed below the select | | `hiddenSelectedOptionsLabel` | `string` | No | `-` | Label to show for showcasing count of hidden selected options | | `hideSearchInput` | `boolean` | No | `-` | Hide the search input | | `hideSelectAll` | `boolean` | No | `-` | Whether to hide the Select All option in multi-select mode | | `label` | `null \| string \| number \| false \| true \| ReactElement> \| Iterable \| ReactPortal` | No | `-` | Label displayed above the control | | `labelVariant` | `inside \| outside` | No | `'outside'` | The variant of the label. Only used when compact is not true. | | `maxSelectedOptionsToShow` | `number` | No | `-` | Maximum number of selected options to show before truncating | | `media` | `ReactElement` | No | `-` | Media rendered at the start of the cell (icon, avatar, image, etc). | | `onSearch` | `((searchText: string) => void)` | No | `-` | Search text change handler | | `open` | `boolean` | No | `-` | Controlled open state of the dropdown | | `placeholder` | `null \| string \| number \| false \| true \| ReactElement> \| Iterable \| ReactPortal` | No | `-` | Placeholder text displayed when no option is selected | | `ref` | `null \| (instance: SelectRef \| null) => void \| RefObject` | No | `-` | - | | `removeSelectedOptionAccessibilityLabel` | `string` | No | `-` | Accessibility label for each chip in a multi-select | | `searchText` | `string` | No | `-` | Controlled search text value | | `selectAllLabel` | `string` | No | `-` | Label for the Select All option in multi-select mode | | `setOpen` | `((open: boolean \| ((open: boolean) => boolean)) => void)` | No | `-` | Callback to update the open state | | `startNode` | `null \| string \| number \| false \| true \| ReactElement> \| Iterable \| ReactPortal` | No | `-` | Adds content to the start of the inner input. Refer to diagram for location of startNode in InputStack component | | `style` | `CSSProperties` | No | `-` | Inline styles for the root element | | `styles` | `{ root?: CSSProperties; control?: CSSProperties \| undefined; controlStartNode?: CSSProperties \| undefined; controlInputNode?: CSSProperties \| undefined; controlValueNode?: CSSProperties \| undefined; controlLabelNode?: CSSProperties \| undefined; controlHelperTextNode?: CSSProperties \| undefined; controlEndNode?: CSSProperties \| undefined; controlBlendStyles?: InteractableBlendStyles \| undefined; dropdown?: CSSProperties \| undefined; option?: CSSProperties \| undefined; optionCell?: CSSProperties \| undefined; optionContent?: CSSProperties \| undefined; optionLabel?: CSSProperties \| undefined; optionDescription?: CSSProperties \| undefined; optionBlendStyles?: InteractableBlendStyles \| undefined; selectAllDivider?: CSSProperties \| undefined; emptyContentsContainer?: CSSProperties \| undefined; emptyContentsText?: CSSProperties \| undefined; optionGroup?: CSSProperties \| undefined; } \| undefined` | No | `-` | Custom styles for different parts of the select | | `testID` | `string` | No | `-` | Test ID for the root element | | `type` | `multi \| single` | No | `-` | Whether the select allows single or multiple selections | | `variant` | `primary \| secondary \| positive \| negative \| foregroundMuted \| foreground` | No | `foregroundMuted` | Determines the sentiment of the input. Because we allow startContent and endContent to be custom ReactNode, the content placed inside these slots will not change colors according to the variant. You will have to add that yourself |