Skip to content

Select

Displays a list of options for the user to pick from.

import {
createListCollection,
Select,
} from '@fintech-sandpit/ui/react';
import '@fintech-sandpit/ui/style/components/select.css';
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 (
<Select
collection={collection}
placeholder="Select 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 | string[]—Controlled value of the select input 1
defaultValuestring | string[]—Default (uncontrolled) value of the select input 1
collectionCollection—Options of the select input
sizeFieldSizemdSize of the select input
multiplebooleanfalseWhether the select input is multiple
clearablebooleanfalseWhether the select input is clearable (a ‘x’ icon is shown)
invalidbooleanfalseWhether the select input is invalid
readOnlybooleanfalseWhether the select input is read only
disabledbooleanfalseWhether the select input is disabled
placeholderstring—Placeholder of the select input
  1. The value type is string for single selection (multiple is false) and string[] for multiple selection (multiple is true).
NameTypeDescription
onValueChange(value: string | string[]) => voidCallback fired when the value changes 1
onValueClear() => voidCallback fired when the value is cleared
  1. The value type is string for single selection (multiple is false) and string[] for multiple selection (multiple is true).
Prop namePropsDescription
ItemText{ item: ListCollectionItem; }Component for the custom item text
type Collection = ListCollection<ListCollectionItem>
type FieldSize = 'sm' | 'md' | 'lg'
type ListCollectionItem = {
label: string;
value: string;
disabled?: boolean;
group?: string;
}