Skip to main content

Select

A pressable field that opens a bottom sheet of options. Fully controlled via value and onChange.

Basic usage

Fruit
function SelectDemo() {
const [value, setValue] = useState('apple');

return (
<Select
label="Fruit"
placeholder="Choose a fruit…"
value={value}
onChange={setValue}
options={[
{ label: 'Apple', value: 'apple' },
{ label: 'Banana', value: 'banana' },
{ label: 'Cherry', value: 'cherry' },
]}
/>
);
}

Invalid & disabled

Country
This field is required
<Select
label="Country"
placeholder="Select a country…"
value={value}
onChange={setValue}
isInvalid
errorText="This field is required"
options={[
{ label: 'India', value: 'in' },
{ label: 'USA', value: 'us' },
]}
/>

Custom icons

By default the trigger shows a plain ▲/▼ glyph and the selected option shows a plain ✓ glyph. Pass icon and checkIcon to use real icons instead: either accepts any component matching TVajraIconComponent.

Fruit
import { ChevronDownIcon, CheckIcon } from '@devraj-labs/vajra-ui-icons';

<Select
label="Fruit"
value={value}
onChange={setValue}
icon={ChevronDownIcon}
checkIcon={CheckIcon}
options={options}
/>

Props

PropTypeDefaultDescription
options{ label: string; value: TValue }[]Required. List of selectable options.
valueTValueCurrently selected value.
onChange(value: TValue) => voidRequired. Called when an option is selected.
placeholderstring'Select…'Text shown when nothing is selected.
labelstringLabel rendered above the field.
errorTextstringHelper text shown below the field when isInvalid.
isInvalidbooleanfalseRenders the field with an error border and shows errorText.
isDisabledbooleanfalseDisables interaction and dims opacity.
selectedColorTVajraColors'primary'Highlight color for the selected option in the sheet.
iconTVajraIconComponentIcon shown at the trailing edge of the trigger, rotated between open/closed state. Defaults to a plain ▲/▼ glyph.
checkIconTVajraIconComponentIcon shown next to the selected option in the sheet. Defaults to a plain ✓ glyph.
testIDstringTest identifier.