Skip to content

Combobox

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

import {
Combobox,
useFilter,
useListCollection,
} from '@fintech-sandpit/ui/react';
const filters = useFilter({
sensitivity: 'base',
});
const {
collection,
filter,
} = useListCollection({
items: [
{ label: 'Dog', value: 'dog', description: 'A dog is known for its loyalty and companionship.', group: 'Mammals' },
{ label: 'Cat', value: 'cat', description: 'A cat is known for its independence and curiosity.', group: 'Mammals' },
{ label: 'Canary', value: 'canary', description: 'A canary is known for its song.', group: 'Birds' },
{ label: 'Parrot', value: 'parrot', description: 'A parrot is known for its intelligence and ability to mimic human speech.', group: 'Birds' },
{ label: 'Goldfish', value: 'goldfish', description: 'A goldfish is known for its beauty and rarity.', group: 'Aquatic' },
{ label: 'Turtle', value: 'turtle', description: 'A turtle is known for its longevity and wisdom.', group: 'Aquatic', disabled: true },
],
filter: filters.contains,
groupBy: item => item.group ?? '',
});
return (
<Combobox
collection={collection}
placeholder="Select a pet, e.g. cat"
ItemText={({ item }) => (
<div className="flex flex-col gap-1">
<span>
{item.label}
</span>
<span className="text-sm text-gray-400 dark:text-gray-600">
{item.description}
</span>
</div>
)}
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
onValueChange(value: string[]) => voidCallback fired when the value changes
onInputValueChange(details: ChangeDetails) => voidCallback fired when the combobox input value changes
Prop namePropsDescription
ItemText{ item: ListCollectionItem; }Component for the custom item text
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'