Skip to content

Combobox

A single input field that combines the functionality of a select and input.

import {
Combobox,
type ListCollectionItem,
useFilter,
useListCollection,
} from '@fintech-sandpit/ui/react';
const filters = useFilter({
sensitivity: 'base',
});
const {
collection,
filter,
} = useListCollection<ListCollectionItem>({
items: [
{ label: 'Dog', value: 'dog', group: 'Mammals' },
{ label: 'Cat', value: 'cat', group: 'Mammals' },
{ label: 'Canary', value: 'canary', group: 'Birds' },
{ label: 'Parrot', value: 'parrot', group: 'Birds' },
{ label: 'Goldfish', value: 'goldfish', group: 'Aquatic' },
{ label: 'Turtle', value: 'turtle', group: 'Aquatic', disabled: true },
],
filter: filters.contains,
groupBy: item => item.group ?? '',
});
return (
<Combobox
collection={collection}
placeholder="Select a pet, e.g. cat"
onInputValueChange={({ inputValue }) => filter(inputValue)}
/>
);
NameTypeDefaultDescription
valuestring[]Controlled value of the combobox
defaultValuestring[]Default (uncontrolled) value of the combobox
collectionCollectionOptions of the combobox
sizeSizemdSize of the combobox
multiplebooleanfalseWhether the combobox is multiple
clearablebooleanfalseWhether the combobox is clearable (a ‘x’ icon is shown)
invalidbooleanfalseWhether the combobox is invalid
readOnlybooleanfalseWhether the combobox is read only
disabledbooleanfalseWhether the combobox is disabled
placeholderstringPlaceholder of the combobox
NameTypeDescription
onChange(value: string[]) => voidCallback fired when the value changes
onInputValueChange(details: ChangeDetails) => voidCallback fired when the combobox input value changes
type Collection = ListCollection<ListCollectionItem>
type ListCollectionItem = {
label: string;
value: string;
disabled?: boolean;
group?: string;
}
type ChangeDetails = {
inputValue: string;
reason?: 'input-change' | 'item-select' | 'clear-trigger' | 'script' | 'interact-outside';
}
type Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl'