Skip to main content

Select

Single Select picker component for primitive and list of objects.

Usage

function SelectUsage() {
const [selectedValue, setSelectedValue] = useState<number | undefined>(-1)

return (
<Select
options={OPTIONS}
value={selectedValue}
onValueChange={(value) => setSelectedValue(value)}
/>
)
}

Default Value

function SelectDefaultValue() {
return <Select options={OPTIONS} defaultValue={3} />
}

SelectClearable

function SelectClearable() {
const [selectedValue, setSelectedValue] = useState<number | undefined>(-1)

return (
<Select
options={OPTIONS}
value={selectedValue}
clearable
onValueChange={(value) => setSelectedValue(value)}
/>
)
}

Disabled

function SelectDisabled() {
const [selectedValue, setSelectedValue] = useState<number | undefined>(-1)

return (
<Select
disabled
options={OPTIONS}
value={selectedValue}
onValueChange={(value) => setSelectedValue(value)}
/>
)
}

List of Objects

function SelectObjectOptions() {
const FRUIT_LIST = [
{
label: 'Red Apple',
value: {id: 1, name: 'Apple'},
},
{
label: 'Orange Orange',
value: {id: 2, name: 'Orange'},
},
{
label: 'Yellow Mango',
value: {id: 3, name: 'Mango'},
},
{
label: 'Yellow Papaya',
value: {id: 4, name: 'Papaya'},
},
]

const [selectedValue, setSelectedValue] = useState<
(typeof FRUIT_LIST)[0]['value'] | undefined
>(undefined)

return (
<Select
options={FRUIT_LIST}
value={selectedValue}
onValueChange={(value, item) => {
setSelectedValue(value)
alert(`Selected Value\n${JSON.stringify(item)}`)
}}
/>
)
}

Props

PropData TypeDefault ValueDescription
ExtendsBaseUIProps--Inherits properties from BaseUIProps
optionsSelectItemT<ItemT>[]--List of options
valueItemT--Selected value from the data objecti.e. pass the `item.value` object that you get from `onValueChange`
defaultValueItemT--Default value from the item.value
displayValuestring--Set custom display value
onValueChange(selectedValue?: ItemT, selectedItem?: SelectItemT<ItemT>, index?: number) => void--Callback on every value change
searchableboolean--Set it true to open keyboard and show search resultsTODO: add support for this
clearableboolean--Show the close icon at right to clear the selection
pickerHeightnumber--Height of the popover shown for selecting the item
pickerPropsPartial<Omit<FlatListProps<SelectItemT<ItemT>>, "data">>--Picker flat list props
renderItemListRenderItem<SelectItemT<ItemT>>--Render a custom view for picker item
inputPropsOmit<TextInputProps, "defaultValue" | "value">--Input props
statusBlossomStatusprimary--
sizeBlossomSizemedium--