Skip to content

Select

Select Primitive

Demo


Presents a selection of options for the user to choose from, activated by a button.

Installation

Terminal window
npx @react-native-reusables/cli@latest add select

Usage

import { useSafeAreaInsets } from 'react-native-safe-area-context';
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectLabel,
SelectTrigger,
SelectValue,
} from '~/components/ui/select';
function Example() {
const insets = useSafeAreaInsets();
const contentInsets = {
top: insets.top,
bottom: insets.bottom,
left: 12,
right: 12,
};
return (
<Select defaultValue={{ value: 'apple', label: 'Apple' }}>
<SelectTrigger className='w-[250px]'>
<SelectValue
className='text-foreground text-sm native:text-lg'
placeholder='Select a fruit'
/>
</SelectTrigger>
<SelectContent insets={contentInsets} className='w-[250px]'>
<SelectGroup>
<SelectLabel>Fruits</SelectLabel>
<SelectItem label='Apple' value='apple'>
Apple
</SelectItem>
<SelectItem label='Banana' value='banana'>
Banana
</SelectItem>
<SelectItem label='Blueberry' value='blueberry'>
Blueberry
</SelectItem>
<SelectItem label='Grapes' value='grapes'>
Grapes
</SelectItem>
<SelectItem label='Pineapple' value='pineapple'>
Pineapple
</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
);
}

Props

Select

Extends View props

PropTypeNote
defaultValueoption: { value: string, label: string } | undefined(optional)
valueoption: { value: string, label: string } | undefined(optional)
onValueChange(option: { value: string, label: string } | undefined ) => void(optional)
onOpenChange(value: boolean) => void(optional)
disabledboolean(optional)
asChildboolean(optional)
dir’ltr’ | ‘rtl’Web only (optional)
namestringWeb only (optional)
requiredbooleanWeb only (optional)

SelectTrigger

Extends Pressable props

PropTypeNote
asChildboolean(optional)

SelectContent

Extends View props

PropTypeNote
asChildboolean(optional)
forceMounttrue | undefined(optional)
alignOffsetnumber(optional)
insetsInsets(optional)
avoidCollisionsboolean(optional)
align’start’ | ‘center’ | ‘end’(optional)
side’top’ | ‘bottom’(optional)
sideOffsetnumber(optional)
disablePositioningStylebooleanNative Only (optional)
position’popper’ | ‘item-aligned’ | undefinedWeb Only (optional)

SelectItem

Extends Pressable props

PropTypeNote
valuestring
labelstring
closeOnPressboolean(optional)
asChildboolean(optional)

SelectGroup

Extends View props

SelectLabel

Extends Text props

SelectSeparator

Extends View props

PropTypeNote
valuestring
labelstring
closeOnPressboolean(optional)
asChildboolean(optional)