Skip to content

Latest commit

History

39 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

npmlicense

React Native Searchable Dropdown

Searchable Dropdown to help you search with in the list (FlatList), and you can pick single item and multiple items.

exampleexample

Installation

npm install --save react-native-searchable-dropdown

Properties

PropsDescription
itemsdropdown items
defaultIndexDefault selected index of items. (optional)
onTextChangeon text change you can passs onTextChange and catch the input text. (optional)
onItemSelecton item selection you can passs onItemSelect and catch the input item.
containerStylecomponent container style
textInputStyleTextInput style
itemStyleitems on dropdown
itemTextStyleitem text
resetValuereset textInput Value with true and false state
placeholdertextInput placeholder
placeholderTextColortextInput placeholderTextColor
itemsContainerStyleitems container style you can pass maxHeight to restrict the items dropdown hieght
underlineColorAndroidTextInput underline height
listProps all supported (FlatList) props example: listProps={ nestedScrollEnabled: true }
textInputProps all supported (TextInput) props example: textInputProps={ underlineColorAndroid: 'transparent' }
setSortfilter data on text changing example: setSort={(item, searchedText)=> item.name.toLowerCase().startsWith(searchedText.toLowerCase())}
multiboolean toggle multi selection
selectedItemsselectedItems of multi selection note: work when if multi prop is true
chipboolean toggle chip display mode note: work when if multi prop is true
onRemoveItem{ (item, index) => { } } note: work when if multi prop is true

Example

importReact,{Component,Fragment}from'react';importSearchableDropdownfrom'react-native-searchable-dropdown';varitems=[{id: 1,name: 'JavaScript',},{id: 2,name: 'Java',},{id: 3,name: 'Ruby',},{id: 4,name: 'React Native',},{id: 5,name: 'PHP',},{id: 6,name: 'Python',},{id: 7,name: 'Go',},{id: 8,name: 'Swift',},];classAppextendsReact.Component{constructor(props){super(props);this.state={selectedItems: [{id: 7,name: 'Go',},{id: 8,name: 'Swift',}]}}render(){return(<Fragment>{/* Multi */}<SearchableDropdownmulti={true}selectedItems={this.state.selectedItems}onItemSelect={(item)=>{constitems=this.state.selectedItems;items.push(item)this.setState({selectedItems: items});}}containerStyle={{padding: 5}}onRemoveItem={(item,index)=>{constitems=this.state.selectedItems.filter((sitem)=>sitem.id!==item.id);this.setState({selectedItems: items});}}itemStyle={{padding: 10,marginTop: 2,backgroundColor: '#ddd',borderColor: '#bbb',borderWidth: 1,borderRadius: 5,}}itemTextStyle={{color: '#222'}}itemsContainerStyle={{maxHeight: 140}}items={items}defaultIndex={2}chip={true}resetValue={false}textInputProps={{placeholder: "placeholder",underlineColorAndroid: "transparent",style: {padding: 12,borderWidth: 1,borderColor: '#ccc',borderRadius: 5,},onTextChange: text=>alert(text)}}listProps={{nestedScrollEnabled: true,}}/>{/* Single */}<SearchableDropdownonItemSelect={(item)=>{constitems=this.state.selectedItems;items.push(item)this.setState({selectedItems: items});}}containerStyle={{padding: 5}}onRemoveItem={(item,index)=>{constitems=this.state.selectedItems.filter((sitem)=>sitem.id!==item.id);this.setState({selectedItems: items});}}itemStyle={{padding: 10,marginTop: 2,backgroundColor: '#ddd',borderColor: '#bbb',borderWidth: 1,borderRadius: 5,}}itemTextStyle={{color: '#222'}}itemsContainerStyle={{maxHeight: 140}}items={items}defaultIndex={2}resetValue={false}textInputProps={{placeholder: "placeholder",underlineColorAndroid: "transparent",style: {padding: 12,borderWidth: 1,borderColor: '#ccc',borderRadius: 5,},onTextChange: text=>alert(text)}}listProps={{nestedScrollEnabled: true,}}/></Fragment>);}}

About

Searchable Dropdown

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages