Select

A Select component allows users to choose from a dropdown list. Built on top of heroui-native Select.

Demo

React Native components render to native views, so this is the component running in the example app, in the theme you are reading in.

9:41
Select running in the Nayan UI example app

Usage

Select.tsx
import { View } from 'react-native';
import { useState } from 'react';
import { NSelect, NText } from '@nayan-ui/native';
export default function SelectScreen() {
const [country, setCountry] = useState('');
return (
<View className="p-4 gap-4">
<NText className="text-lg font-bold">Basic</NText>
<NSelect
label="Country"
placeholder="Select a country"
items={[
{ label: 'India', value: 'in' },
{ label: 'USA', value: 'us' },
{ label: 'UK', value: 'uk' },
{ label: 'Germany', value: 'de' },
{ label: 'Japan', value: 'jp' }
]}
onValueChange={setCountry}
/>
<NText>Selected: {country || '—'}</NText>
<NText className="text-lg font-bold">With default value</NText>
<NSelect
label="Language"
defaultValue={{ label: 'English', value: 'en' }}
items={[
{ label: 'English', value: 'en' },
{ label: 'Spanish', value: 'es' },
{ label: 'French', value: 'fr' }
]}
onValueChange={() => {}}
/>
<NText className="text-lg font-bold">Disabled</NText>
<NSelect label="Locked" isDisabled items={[{ label: 'Only option', value: 'only' }]} onValueChange={() => {}} />
</View>
);
}

Attributes

14 props
NameTypeDefaultDetails
itemsSelectOption[]RequiredArray of select options with label and value.
onValueChange(value: string) => voidRequiredCallback when selection changes (returns the value string).
labelstringOptionalLabel above the select.
selectLabelstringOptionalLabel shown inside the dropdown list.
placeholderstringOptionalPlaceholder text for the select trigger.
defaultValueSelectOptionOptionalDefault selected option.
isDisabledbooleanfalseWhether the select is disabled.
containerClassNamestring' 'You can customise container by passing tailwind classes.
labelClassNamestring' 'You can customise label by passing tailwind classes.
triggerClassNamestring' 'You can customise trigger by passing tailwind classes.
disabledbooleanfalseAlias of isDisabled.
valueSelectOptionOptionalControlled selected option.
optionsSelectOption[]OptionalAlias of items.
onChange(value: string) => voidOptionalAlias of onValueChange.

Tags

Other components solving nearby problems.