Skip to content

Repository files navigation

NPM

npm versionGitHub starsCodeQLRelease & Publish to NPMcoverage

react-native-input-select

A fully customizable dropdown selection package for react-native android and iOS with multiple select and search capabilities.

Installation

With npm

npm install react-native-input-select

With yarn

yarn add react-native-input-select

Sandbox

See more examples in Sandbox

iOS

Screenshot 2023-07-08 at 12 34 23 AMScreenshot 2023-07-08 at 12 39 51 AMScreenshot 2023-07-08 at 12 29 16 AM
Screenshot 2023-07-08 at 12 28 57 AMScreenshot 2023-07-08 at 12 20 52 AMScreenshot 2023-07-08 at 12 21 06 AM

Android

Screenshot 2023-05-16 at 6 17 09 AMScreenshot 2023-03-23 at 5 26 58 PMScreenshot 2023-03-23 at 5 28 49 PM

⚠️ Important: Wrap Your App in SafeAreaProvider

Starting from recent versions of React Native, certain safe area utilities have been deprecated, which may cause layout issues or warnings if not configured properly.

To ensure consistent behavior across devices (especially on iOS with notches and status bars), you must wrap your root component with SafeAreaProvider from react-native-safe-area-context.

✅ Example Setup

import{SafeAreaProvider}from'react-native-safe-area-context';importAppfrom'./App';exportdefaultfunctionRoot(){return(<SafeAreaProvider><App/></SafeAreaProvider>);}

Basic Usage

importReactfrom'react';importDropdownfrom'react-native-input-select';exportdefaultfunctionApp(){const[country,setCountry]=React.useState();return(<Dropdownlabel="Country"placeholder="Select an option..."options={[{label: 'Nigeria',value: 'NG'},{label: 'Åland Islands',value: 'AX'},{label: 'Algeria',value: 'DZ'},{label: 'American Samoa',value: 'AS'},{label: 'Andorra',value: 'AD'},]}selectedValue={country}onValueChange={(value)=>setCountry(value)}primaryColor={'green'}/>);}

Advanced Usage With Flat List

importReactfrom'react';importDropdownfrom'react-native-input-select';import{View,StyleSheet,Text,Button,Alert,Image}from'react-native';exportdefaultfunctionApp(){const[country,setCountry]=React.useState();return(<Dropdownlabel="Customized components in list"placeholder="Select multiple countries..."options={countries.slice(0,30)}optionLabel={'name'}optionValue={'code'}selectedValue={country}onValueChange={(itemValue: any)=>setCountry(itemValue)}isMultipleisSearchableprimaryColor={'orange'}dropdownStyle={{borderWidth: 0,// To remove border, set borderWidth to 0}}dropdownIcon={<Imagestyle={styles.tinyLogo}source={{uri: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADMAAAAzCAYAAAA6oTAqAAAAEXRFWHRTb2Z0d2FyZQBwbmdjcnVzaEB1SfMAAABQSURBVGje7dSxCQBACARB+2/ab8BEeQNhFi6WSYzYLYudDQYGBgYGBgYGBgYGBgYGBgZmcvDqYGBgmhivGQYGBgYGBgYGBgYGBgYGBgbmQw+P/eMrC5UTVAAAAABJRU5ErkJggg==',}}/>}dropdownIconStyle={{top: 20,right: 20}}listHeaderComponent={<Viewstyle={styles.customComponentContainer}><Textstyle={styles.text}>
💡 You can add any component to the top of this list
</Text><Viewstyle={styles.fixToText}><Buttontitle="Left button"onPress={()=>Alert.alert('Left button pressed')}color="#007AFF"/><Buttontitle="Right button"onPress={()=>Alert.alert('Right button pressed')}/></View></View>}listFooterComponent={<Viewstyle={styles.customComponentContainer}><Text>You can add any component to the bottom of this list</Text></View>}modalControls={{modalOptionsContainerStyle: {padding: 10,backgroundColor: 'cyan',},modalProps: {supportedOrientations: ['portrait','portrait-upside-down','landscape','landscape-left','landscape-right',],transparent: false,},}}listComponentStyles={{listEmptyComponentStyle: {color: 'red',},itemSeparatorStyle: {opacity: 0,borderColor: 'white',borderWidth: 2,backgroundColor: 'cyan',},sectionHeaderStyle: {padding: 10,backgroundColor: 'cyan',},}}listControls={{selectAllText: 'Choose everything',unselectAllText: 'Remove everything',selectAllCallback: ()=>Alert.alert('You selected everything'),unselectAllCallback: ()=>Alert.alert('You removed everything'),emptyListMessage: 'No record found',}}selectedItemsControls={{removeItemIcon: (<Imagesource={{uri: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA',}}style={{tintColor: 'white',height: 12,width: 12}}/>),onRemoveItem: ()=>Alert.alert('Item was removed'),showRemoveIcon: true,}}/>);}conststyles=StyleSheet.create({customComponentContainer: {paddingHorizontal: 20,paddingVertical: 10,},text: {marginBottom: 20,},fixToText: {flexDirection: 'row',justifyContent: 'space-between',},tinyLogo: {width: 20,height: 20,},radioButton: {width: 20,height: 20,borderRadius: 20/2,borderWidth: 3,borderColor: 'white',},});

Advanced Usage with Section List

<DropdownSelectlabel="Menu"placeholder="Select multiple dishes..."options={[{title: 'Main dishes',data: [{label: 'Pizza',value: 'A'},{label: 'Burger',value: 'B'},{label: 'Risotto',value: 'C'},],},{title: 'Sides',data: [{label: 'Ice cream',value: 'D'},{label: 'Cheesecake',value: 'E'},],},{title: 'Drinks',data: [{label: 'Water',value: 'F'},{label: 'Coke',value: 'G'},{label: 'Juice',value: 'H'},],},]}selectedValue={menu}onValueChange={(itemValue: any)=>setMenu(itemValue)}isMultipleisSearchableprimaryColor={'deepskyblue'}listComponentStyles={{sectionHeaderStyle: {padding: 10,backgroundColor: 'green',color: 'white',width: '30%',},}}/>

For more examples visit our wiki page

Props

ProptypesDatatypeExample
labelstring or ReactComponentCountries or <Text> You can add any component here <Text>
placeholderstringSelect a country
optionsArray[{ name: 'Nigeria', code: 'NG' }, { name: 'Albania', code: 'AL' }]
optionLabelstringname
optionValuestringcode
errorstringThis is a requiredfield
helperTextstringOnly few countries are listed
selectedValuestring or ArrayAL or [AL, AX]
onValueChangefunction()=>{}
isMultipleBooleantrue
isSearchableBooleantrue
disabledBooleantrue
dropdownIconReact ComponentImage or <Text> Show <Text>
labelStyleObject{color: 'red', fontSize: 15, fontWeight: '500'}
placeholderStyleObject{color: 'blue', fontSize: 15, fontWeight: '500'}
dropdownStyleObject{borderColor: 'blue', margin: 5, borderWidth:0 ...}
dropdownContainerStyleObject{backgroundColor: 'red', width: '30%', ...}
dropdownIconStyleObject{top: 10 , right: 10, ...}
selectedItemStyleObject{fontWeight: '600', color: 'yellow', ...}
multipleSelectedItemStyleObject{backgroundColor: 'red', color: 'yellow', ...}
dropdownErrorStyleObject{borderWidth: 2, borderStyle: 'solid'}
dropdownErrorTextStyleObject{color: 'red', fontWeight:'500'}
dropdownHelperTextStyleObject{color: 'green', fontWeight:'500'}
primaryColorstringblue
autoCloseOnSelectbooleanfalse
listHeaderComponentReact Component<Text> You can add any component here </Text>
listFooterComponentReact Component<Text> You can add any component here <Text>
listComponentStylesObject{listEmptyComponentStyle: ViewStyle, itemSeparatorStyle: ViewStyle, sectionHeaderStyle: TextStyle}
listEmptyComponentReact Component<Text> You can add any component here <Text>
checkboxControlsObject{checkboxSize: number, checkboxStyle: ViewStyle, checkboxLabelStyle: TextStyle, checkboxComponent?: React.ReactNode, checkboxDisabledStyle?: ViewStyle, checkboxUnselectedColor?: ColorValue}
listControlsObject{ selectAllText: 'Choose all', unselectAllText: 'Remove all', selectAllCallback: () => {}, unselectAllCallback: () => {}, hideSelectAll: boolean, emptyListMessage: 'No record found', keyboardShouldPersistTaps: "always" }
searchControlsObject{ textInputStyle: ViewStyle | TextStyle, textInputContainerStyle: ViewStyle, textInputProps: TextInputProps, searchCallback:(value)=>{}}
modalControlsObject{ modalBackgroundStyle: ViewStyle, modalOptionsContainerStyle: ViewStyle, modalProps: ModalProps}
minSelectableItemsnumber3
maxSelectableItemsnumber5
selectedItemsControlsObject{ removeItemIcon: ReactNode, onRemoveItem: ()=>{}, showRemoveIcon: boolean}
refuseRef<DropdownSelectHandle | null>(null)Use this to open or close the modal as needed e.g dropdownRef.current?.open() or dropdownRef.current?.close()

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

Made with contrib.rocks.

Discussion

For discussion and feedback on this library. You can access it by heading over to the Discussions Tab on Github. We've created some sections to keep the discussion focused.

TitleTopic
Announcements 📣General announcements about this library.
Show and tell 🙌Show off something you've made out of this library
Ideas 💡A place to Share ideas for new features.
Polls 🗳️Take a vote from the community
Q&A 🤝A place to ask the community for help on the New Architecture topics
General 💬Chat about anything and everything here

License

MIT

Video Demo

utt.mov

About

A customizable dropdown selection package for react-native android, iOS and web with multiple select and search capabilities. Look is consistent across platforms. Compatible with Expo.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

170 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages