Skip to content

ListBox

A component for selecting a single or multiple items from a list.

import {
createListCollection,
ListBox,
} from '@fintech-sandpit/ui/react';
const collection = createListCollection({
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 },
],
groupBy: item => item.group ?? '',
});
return (
<ListBox
collection={collection}
label="Choose a pet"
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>
)}
/>
);
NameTypeDefaultDescription
valuestring[]The value of the list box
defaultValuestring[]The default value of the list box
collectionCollectionThe collection of the list box
labelstringThe label of the list box
sizeSizemdThe size of the list box
requiredbooleanfalseWhether the list box is required
multiplebooleanfalseWhether the list box selection can contain multiple items
invalidbooleanfalseWhether the list box is invalid
disabledbooleanfalseWhether the list box is disabled
NameTypeDescription
onSelect(value: string) => voidCallback fired when an item is selected
onValueChange(value: string[]) => voidCallback fired when the 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 Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl'