Skip to content

ListBox

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

import {
createListCollection,
ListBox,
type ListCollectionItem,
} from '@fintech-sandpit/ui/react';
const collection = createListCollection<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 },
],
groupBy: item => item.group ?? '',
});
return (
<ListBox
collection={collection}
label="Choose a pet"
/>
);
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
onChange(value: string[]) => voidCallback fired when the value changes
onSelect(value: string) => voidCallback fired when an item is selected
type Collection = ListCollection<ListCollectionItem>
type ListCollectionItem = {
label: string;
value: string;
disabled?: boolean;
group?: string;
}
type Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl'