4.0.1 • Published 24 days ago

react-native-select-dropdown v4.0.1

Weekly downloads
227
License
MIT
Repository
github
Last release
24 days ago

react-native-select-dropdown

react-native-select-dropdown is a highly customized dropdown | select | picker | menu for react native that works for android and iOS platforms.

Installation

# Using npm

npm install react-native-select-dropdown

# Using yarn

yarn add react-native-select-dropdown

Demo

Code provided in Examples folder.

Search Functionality (Code provided in Examples folder).

🚀 Major Changes

Version 4.0

  • (defaultButtonText, buttonTextAfterSelection, buttonStyle, buttonTextStyle, renderCustomizedButtonChild, renderDropdownIcon, dropdownIconPosition) have been removed and (renderButton) has been added to customize dropdown button
  • (rowTextForSelection, rowStyle, rowTextStyle, selectedRowStyle, selectedRowTextStyle, renderCustomizedRowChild) have been removed and (renderItem) has been added to customize each dropdown item
  • testID added to scroll the dropdown menu in e2e tests.
  • Most of issues have been fixed.
  • Updated readme.md file
  • More examples in examples folder.

Usage

import SelectDropdown from 'react-native-select-dropdown'
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
...
  const emojisWithIcons = [
    {title: 'happy', icon: 'emoticon-happy-outline'},
    {title: 'cool', icon: 'emoticon-cool-outline'},
    {title: 'lol', icon: 'emoticon-lol-outline'},
    {title: 'sad', icon: 'emoticon-sad-outline'},
    {title: 'cry', icon: 'emoticon-cry-outline'},
    {title: 'angry', icon: 'emoticon-angry-outline'},
    {title: 'confused', icon: 'emoticon-confused-outline'},
    {title: 'excited', icon: 'emoticon-excited-outline'},
    {title: 'kiss', icon: 'emoticon-kiss-outline'},
    {title: 'devil', icon: 'emoticon-devil-outline'},
    {title: 'dead', icon: 'emoticon-dead-outline'},
    {title: 'wink', icon: 'emoticon-wink-outline'},
    {title: 'sick', icon: 'emoticon-sick-outline'},
    {title: 'frown', icon: 'emoticon-frown-outline'},
  ];
...
  <SelectDropdown
    data={emojisWithIcons}
    onSelect={(selectedItem, index) => {
      console.log(selectedItem, index);
    }}
    renderButton={(selectedItem, isOpened) => {
      return (
        <View style={styles.dropdownButtonStyle}>
          {selectedItem && (
            <Icon name={selectedItem.icon} style={styles.dropdownButtonIconStyle} />
          )}
          <Text style={styles.dropdownButtonTxtStyle}>
            {(selectedItem && selectedItem.title) || 'Select your mood'}
          </Text>
          <Icon name={isOpened ? 'chevron-up' : 'chevron-down'} style={styles.dropdownButtonArrowStyle} />
        </View>
      );
    }}
    renderItem={(item, index, isSelected) => {
      return (
        <View style={{...styles.dropdownItemStyle, ...(isSelected && {backgroundColor: '#D2D9DF'})}}>
          <Icon name={item.icon} style={styles.dropdownItemIconStyle} />
          <Text style={styles.dropdownItemTxtStyle}>{item.title}</Text>
        </View>
      );
    }}
    showsVerticalScrollIndicator={false}
    dropdownStyle={styles.dropdownMenuStyle}
  />
...
  const styles = StyleSheet.create({
    dropdownButtonStyle: {
      width: 200,
      height: 50,
      backgroundColor: '#E9ECEF',
      borderRadius: 12,
      flexDirection: 'row',
      justifyContent: 'center',
      alignItems: 'center',
      paddingHorizontal: 12,
    },
    dropdownButtonTxtStyle: {
      flex: 1,
      fontSize: 18,
      fontWeight: '500',
      color: '#151E26',
    },
    dropdownButtonArrowStyle: {
      fontSize: 28,
    },
    dropdownButtonIconStyle: {
      fontSize: 28,
      marginRight: 8,
    },
    dropdownMenuStyle: {
      backgroundColor: '#E9ECEF',
      borderRadius: 8,
    },
    dropdownItemStyle: {
      width: '100%',
      flexDirection: 'row',
      paddingHorizontal: 12,
      justifyContent: 'center',
      alignItems: 'center',
      paddingVertical: 8,
    },
    dropdownItemTxtStyle: {
      flex: 1,
      fontSize: 18,
      fontWeight: '500',
      color: '#151E26',
    },
    dropdownItemIconStyle: {
      fontSize: 28,
      marginRight: 8,
    },
  });

Props

Methods


data

array of data that will be represented in dropdown 'can be array of objects

TypeRequired
arrayYes

onSelect

function recieves selected item and its index in data array

TypeRequired
functionYes

renderButton

function returns React component for the dropdown button

TypeRequired
functionYes

renderItem

function returns React component for each dropdown item

TypeRequired
functionYes

defaultValue

default selected item in dropdown ( check examples in Demo1)

TypeRequired
anyNo

defaultValueByIndex

default selected item index

TypeRequired
integerNo

disabled

disable dropdown

TypeRequired
booleanNo

disabledIndexes

array of disabled items index

TypeRequired
arrayNo

disableAutoScroll

disable auto scroll to selected value

TypeRequired
booleanNo

testID

dropdown menu testID

TypeRequired
stringNo

onFocus

function fires when dropdown is opened

TypeRequired
functionNo

onBlur

function fires when dropdown is closed

TypeRequired
functionNo

onScrollEndReached

function fires when dropdown scrolls to the end (for paginations)

TypeRequired
functionNo

statusBarTranslucent

required to set true when statusbar is translucent (android only)

TypeRequired
booleanNo

dropdownStyle

style object for dropdown view

TypeRequired
objectNo

dropdownOverlayColor

backdrop color when dropdown is opened

TypeRequired
stringNo

showsVerticalScrollIndicator

When true, shows a vertical scroll indicator.

TypeRequired
booleanNo

search

enable search functionality

TypeRequired
booleanNo

searchInputStyle

style object for search input

TypeRequired
objectNo

searchInputTxtColor

text color for search input

TypeRequired
stringNo

searchInputTxtStyle

style object for search input text

TypeRequired
objectNo

searchPlaceHolder

placeholder text for search input

TypeRequired
stringNo

searchPlaceHolderColor

text color for search input placeholder

TypeRequired
stringNo

renderSearchInputLeftIcon

function returns React component for search input icon

TypeRequired
functionNo

renderSearchInputRightIcon

function returns React component for search input icon

TypeRequired
functionNo

onChangeSearchInputText

function callback when the search input text changes, this will automatically disable the dropdown's internal search to be implemented manually outside the component

TypeRequired
functionNo

MethodDescription
reset()Remove selection & reset it
openDropdown()Open the dropdown.
closeDropdown()Close the dropdown.
selectIndex(index)Select a specific item by index.

License

MIT

4.0.1

24 days ago

4.0.0

1 month ago

3.4.0

9 months ago

3.3.4

11 months ago

3.3.1

1 year ago

3.3.0

1 year ago

3.3.3

1 year ago

3.3.2

1 year ago

3.2.1

1 year ago

3.0.3

1 year ago

3.2.0

1 year ago

3.0.2

1 year ago

3.1.0

1 year ago

3.0.1

2 years ago

3.0.0

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.4

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.13.0

2 years ago

1.12.0

2 years ago

1.9.0

2 years ago

1.11.0

2 years ago

1.10.0

2 years ago

1.8.0

2 years ago

1.7.0

2 years ago

1.6.0

2 years ago

1.5.0

2 years ago

1.4.0

2 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.0

3 years ago