Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-element-dropdown

Package Overview
Dependencies
Maintainers
1
Versions
125
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-element-dropdown

A react-native dropdown component easy to customize for both iOS and Android.

  • 1.5.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
72K
decreased by-18.11%
Maintainers
1
Weekly downloads
 
Created
Source

react-native-element-dropdown

A React Native dropdown component easy to customize for both iOS and Android.

Features

  • Dropdown and Multiselect in one package
  • Easy to use
  • Consistent look and feel on iOS and Android
  • Customizable font size, colors and animation duration
  • Implemented with typescript

Getting started

    npm install react-native-element-dropdown --save

or

    yarn add react-native-element-dropdown
Source code demo

react-native-template-components A beautiful template for React Native.

Demo

Dropdown Props
PropsParamsisRequireDescription
dataArrayYesData is a plain array
labelFieldStringYesExtract the label from the data item
valueFieldStringYesExtract the primary key from the data item
onChange(item) => voidYesSelection callback
valueItemNoSelected value
placeholderStringNoThe string that will be rendered before dropdown has been selected
placeholderStyleTextStyleNoStyling for text placeholder
selectedTextStyleTextStyleNoStyling for selected text
selectedTextPropsTextPropsNoText Props for selected text. Ex: numberOfLines={1}
styleViewStyleNoStyling for container view
containerStyleViewStyleNoStyling for container list
maxHeightNumberNoCustomize height for container list
fontFamilyStringNoCustomize font style
iconColorStringNoColor of icons
activeColorStringNoBackground color for item selected in container list
searchBooleanNoShow or hide input search
inputSearchStyleViewStyleNoStyling for input search
searchPlaceholderStringNoThe string that will be rendered before text input has been entered
renderInputSearch(onSearch: (text:string) => void) => JSX.ElementNoCustomize TextInput search
disableBooleanNoSpecifies the disabled state of the Dropdown
dropdownPosition'auto' or 'top' or 'bottom'NoDropdown list position. Default is 'auto'
autoScrollBooleanNoAuto scroll to index item selected, default is true
showsVerticalScrollIndicatorBooleanNoWhen true, shows a vertical scroll indicator, default is true
renderLeftIcon() => JSX.ElementNoCustomize left icon for dropdown
renderRightIcon() => JSX.ElementNoCustomize right icon for dropdown
renderItem(item) => JSX.ElementNoTakes an item from data and renders it into the list
onFocus() => voidNoCallback that is called when the dropdown is focused
onBlur() => voidNoCallback that is called when the dropdown is blurred
MultiSelect Props
PropsParamsisRequireDescription
dataArrayYesData is a plain array
labelFieldStringYesExtract the label from the data item
valueFieldStringYesExtract the primary key from the data item
onChange(value[]) => voidYesSelection callback
valueItem[]NoSelected value
placeholderStringNoThe string that will be rendered before dropdown has been selected
placeholderStyleTextStyleNoStyling for text placeholder
styleViewStyleNoStyling for container view
containerStyleViewStyleNoStyling for container list
maxHeightNumberNoCustomize height for container list
fontFamilyStringNoCustomize font style
iconColorStringNoColor of icons
activeColorStringNoBackground color for item selected in container list
selectedStyleViewStyleNoStyling for selected view
selectedTextStyleTextStyleNoStyling for selected text
renderSelectedItem(item, unSelect?: (item) => void) => JSX.ElementNoTakes an item from data and renders it into the list selected
searchBooleanNoShow or hide input search
inputSearchStyleViewStyleNoStyling for input search
searchPlaceholderStringNoThe string that will be rendered before text input has been entered
renderInputSearch(onSearch: (text:string) => void) => JSX.ElementNoCustomize TextInput search
disableBooleanNoSpecifies the disabled state of the Dropdown
dropdownPosition'auto' or 'top' or 'bottom'NoDropdown list position. Default is 'auto'
showsVerticalScrollIndicatorBooleanNoWhen true, shows a vertical scroll indicator, default is true
renderLeftIcon() => JSX.ElementNoCustomize left icon for dropdown
renderRightIcon() => JSX.ElementNoCustomize right icon for dropdown
renderItem(item) => JSX.ElementNoTakes an item from data and renders it into the list
onFocus() => voidNoCallback that is called when the dropdown is focused
onBlur() => voidNoCallback that is called when the dropdown is blurred
SelectCountry extends Dropdown
PropsParamsisRequireDescription
imageFieldStringYesExtract the image from the data item
imageStyleImageStyleNoStyling for image

Dropdown example

  import React, { useState } from 'react';
  import { StyleSheet, Text, View } from 'react-native';
  import { Dropdown } from 'react-native-element-dropdown';
  import AntDesign from 'react-native-vector-icons/AntDesign';

  const data = [
    { label: 'Item 1', value: '1' },
    { label: 'Item 2', value: '2' },
    { label: 'Item 3', value: '3' },
    { label: 'Item 4', value: '4' },
    { label: 'Item 5', value: '5' },
    { label: 'Item 6', value: '6' },
    { label: 'Item 7', value: '7' },
    { label: 'Item 8', value: '8' },
  ];

  const DropdownComponent = () => {
    const [value, setValue] = useState(null);
    const [isFocus, setIsFocus] = useState(false);

    const renderLabel = () => {
      if (value || isFocus) {
        return (
          <Text style={[styles.label, isFocus && { color: 'blue' }]}>
            Dropdown label
          </Text>
        );
      }
      return null;
    };

    return (
      <View style={styles.container}>
        {renderLabel()}
        <Dropdown
          style={[styles.dropdown, isFocus && { borderColor: 'blue' }]}
          data={data}
          search
          labelField="label"
          valueField="value"
          placeholder={!isFocus ? 'Select item' : '...'}
          searchPlaceholder="Search..."
          value={value}
          onFocus={() => setIsFocus(true)}
          onBlur={() => setIsFocus(false)}
          onChange={item => {
            setValue(item.value);
            setIsFocus(false);
          }}
          renderLeftIcon={() => (
            <AntDesign
              style={styles.icon}
              color={isFocus ? 'blue' : 'black'}
              name="Safety"
              size={20}
            />
          )}
        />
      </View>
    );
  };

  export default DropdownComponent;

  const styles = StyleSheet.create({
    container: {
      padding: 16,
      backgroundColor: 'white',
    },
    dropdown: {
      height: 50,
      borderColor: 'gray',
      borderWidth: 0.5,
      borderRadius: 8,
      paddingHorizontal: 8,
    },
    icon: {
      marginRight: 5,
    },
    label: {
      position: 'absolute',
      backgroundColor: 'white',
      left: 32,
      top: 8,
      zIndex: 999,
      paddingHorizontal: 8,
    },
  });

Dropdown example 1

  import React, { useState } from 'react';
  import { StyleSheet } from 'react-native';
  import { Dropdown } from 'react-native-element-dropdown';
  import AntDesign from 'react-native-vector-icons/AntDesign';

  const data = [
    { label: 'Item 1', value: '1' },
    { label: 'Item 2', value: '2' },
    { label: 'Item 3', value: '3' },
    { label: 'Item 4', value: '4' },
    { label: 'Item 5', value: '5' },
    { label: 'Item 6', value: '6' },
    { label: 'Item 7', value: '7' },
    { label: 'Item 8', value: '8' },
  ];

  const DropdownComponent = () => {
    const [value, setValue] = useState(null);

    return (
      <Dropdown
        style={styles.dropdown}
        data={data}
        search
        labelField="label"
        valueField="value"
        placeholder="Select item"
        searchPlaceholder="Search..."
        value={value}
        onChange={item => {
          setValue(item.value);
        }}
        renderLeftIcon={() => (
          <AntDesign style={styles.icon} color="black" name="Safety" size={20} />
        )}
      />
    );
  };

  export default DropdownComponent;

  const styles = StyleSheet.create({
    dropdown: {
      height: 50,
      borderBottomColor: 'gray',
      borderBottomWidth: 0.5,
      margin: 20,
    },
    icon: {
      marginRight: 5,
    },
  });

Dropdown example 2

  import React, { useState } from 'react';
  import { StyleSheet, View, Text } from 'react-native';
  import { Dropdown } from 'react-native-element-dropdown';
  import AntDesign from 'react-native-vector-icons/AntDesign';

  const data = [
    { label: 'Item 1', value: '1' },
    { label: 'Item 2', value: '2' },
    { label: 'Item 3', value: '3' },
    { label: 'Item 4', value: '4' },
    { label: 'Item 5', value: '5' },
    { label: 'Item 6', value: '6' },
    { label: 'Item 7', value: '7' },
    { label: 'Item 8', value: '8' },
  ];

  const DropdownComponent = () => {
    const [value, setValue] = useState(null);

    const renderItem = (item: any) => {
      return (
        <View style={styles.item}>
          <Text style={styles.textItem}>{item.label}</Text>
          {item.value === value && (
            <AntDesign
              style={styles.icon}
              color="black"
              name="Safety"
              size={20}
            />
          )}
        </View>
      );
    };

    return (
      <Dropdown
        style={styles.dropdown}
        data={data}
        search
        labelField="label"
        valueField="value"
        placeholder="Select item"
        searchPlaceholder="Search..."
        value={value}
        onChange={item => {
          setValue(item.value);
        }}
        renderLeftIcon={() => (
          <AntDesign style={styles.icon} color="black" name="Safety" size={20} />
        )}
        renderItem={renderItem}
      />
    );
  };

  export default DropdownComponent;

  const styles = StyleSheet.create({
    dropdown: {
      height: 50,
      margin: 20,
      backgroundColor: 'white',
      borderRadius: 12,
      padding: 12,
      shadowColor: '#000',
      shadowOffset: {
        width: 0,
        height: 1,
      },
      shadowOpacity: 0.2,
      shadowRadius: 1.41,

      elevation: 2,
    },
    icon: {
      marginRight: 5,
    },
    item: {
      padding: 17,
      flexDirection: 'row',
      justifyContent: 'space-between',
      alignItems: 'center',
    },
    textItem: {
      flex: 1,
      fontSize: 16,
    },
  });

MultiSelect example 1

  import React, { useState } from 'react';
  import { StyleSheet, View } from 'react-native';
  import { MultiSelect } from 'react-native-element-dropdown';
  import AntDesign from 'react-native-vector-icons/AntDesign';

  const data = [
    { label: 'Item 1', value: '1' },
    { label: 'Item 2', value: '2' },
    { label: 'Item 3', value: '3' },
    { label: 'Item 4', value: '4' },
    { label: 'Item 5', value: '5' },
    { label: 'Item 6', value: '6' },
    { label: 'Item 7', value: '7' },
    { label: 'Item 8', value: '8' },
  ];

  const MultiSelectComponent = () => {
    const [selected, setSelected] = useState([]);

    return (
      <View style={styles.container}>
        <MultiSelect
          style={styles.dropdown}
          data={data}
          labelField="label"
          valueField="value"
          placeholder="Select item"
          value={selected}
          onChange={item => {
            setSelected(item);
          }}
          renderLeftIcon={() => (
            <AntDesign
              style={styles.icon}
              color="black"
              name="Safety"
              size={20}
            />
          )}
          selectedStyle={styles.selectedStyle}
        />
      </View>
    );
  };

  export default MultiSelectComponent;

  const styles = StyleSheet.create({
    container: { margin: 16 },
    dropdown: {
      height: 50,
      backgroundColor: 'transparent',
      borderBottomColor: 'gray',
      borderBottomWidth: 0.5,
    },
    icon: {
      marginRight: 5,
    },
    selectedStyle: {
      borderRadius: 14,
    },
  });

MultiSelect example 2

  import React, { useState } from 'react';
  import { StyleSheet, View, TouchableOpacity, Text } from 'react-native';
  import { MultiSelect } from 'react-native-element-dropdown';
  import AntDesign from 'react-native-vector-icons/AntDesign';

  const data = [
    { label: 'Item 1', value: '1' },
    { label: 'Item 2', value: '2' },
    { label: 'Item 3', value: '3' },
    { label: 'Item 4', value: '4' },
    { label: 'Item 5', value: '5' },
    { label: 'Item 6', value: '6' },
    { label: 'Item 7', value: '7' },
    { label: 'Item 8', value: '8' },
  ];

  const MultiSelectComponent = () => {
    const [selected, setSelected] = useState([]);

    const renderItem = (item: any) => {
      return (
        <View style={styles.item}>
          <Text style={styles.textItem}>{item.label}</Text>
          <AntDesign style={styles.icon} color="black" name="Safety" size={20} />
        </View>
      );
    };

    return (
      <View style={styles.container}>
        <MultiSelect
          style={styles.dropdown}
          data={data}
          labelField="label"
          valueField="value"
          placeholder="Select item"
          value={selected}
          onChange={item => {
            setSelected(item);
          }}
          renderLeftIcon={() => (
            <AntDesign
              style={styles.icon}
              color="black"
              name="Safety"
              size={20}
            />
          )}
          renderItem={renderItem}
          renderSelectedItem={(item, unSelect) => (
            <TouchableOpacity onPress={() => unSelect && unSelect(item)}>
              <View style={styles.selectedStyle}>
                <Text style={styles.textSelectedStyle}>{item.label}</Text>
                <AntDesign color="black" name="delete" size={17} />
              </View>
            </TouchableOpacity>
          )}
        />
      </View>
    );
  };

  export default MultiSelectComponent;

  const styles = StyleSheet.create({
    container: { margin: 16 },
    dropdown: {
      height: 50,
      backgroundColor: 'white',
      borderRadius: 12,
      padding: 12,
      shadowColor: '#000',
      shadowOffset: {
        width: 0,
        height: 1,
      },
      shadowOpacity: 0.2,
      shadowRadius: 1.41,

      elevation: 2,
    },
    icon: {
      marginRight: 5,
    },
    item: {
      padding: 17,
      flexDirection: 'row',
      justifyContent: 'space-between',
      alignItems: 'center',
    },
    textItem: {
      flex: 1,
      fontSize: 16,
    },
    selectedStyle: {
      flexDirection: 'row',
      justifyContent: 'center',
      alignItems: 'center',
      borderRadius: 14,
      backgroundColor: 'white',
      shadowColor: '#000',
      marginTop: 8,
      marginRight: 12,
      paddingHorizontal: 12,
      paddingVertical: 8,
      shadowOffset: {
        width: 0,
        height: 1,
      },
      shadowOpacity: 0.2,
      shadowRadius: 1.41,

      elevation: 2,
    },
    textSelectedStyle: {
      marginRight: 5,
    },
  });

SelectCountry example 1

  import React, { useState } from 'react';
  import { StyleSheet, View } from 'react-native';
  import { SelectCountry } from 'react-native-element-dropdown';

  const local_data = [
    {
      value: '1',
      lable: 'Country 1',
      image: {
        uri: 'https://www.vigcenter.com/public/all/images/default-image.jpg',
      },
    },
    {
      value: '2',
      lable: 'Country 2',
      image: {
        uri: 'https://www.vigcenter.com/public/all/images/default-image.jpg',
      },
    },
    {
      value: '3',
      lable: 'Country 3',
      image: {
        uri: 'https://www.vigcenter.com/public/all/images/default-image.jpg',
      },
    },
    {
      value: '4',
      lable: 'Country 4',
      image: {
        uri: 'https://www.vigcenter.com/public/all/images/default-image.jpg',
      },
    },
    {
      value: '5',
      lable: 'Country 5',
      image: {
        uri: 'https://www.vigcenter.com/public/all/images/default-image.jpg',
      },
    },
  ];

  export interface Props {}

  const SelectCountryScreen: React.FC<Props> = _props => {
    const [country, setCountry] = useState('1');

    return (
      <View style={styles.container}>
        <SelectCountry
          style={styles.dropdown}
          selectedTextStyle={styles.selectedText}
          search
          value={country}
          data={local_data}
          valueField="value"
          labelField="lable"
          imageField="image"
          placeholder="Select country"
          searchPlaceholder="Search..."
          onChange={e => {
            setCountry(e.value);
          }}
        />
      </View>
    );
  };

  export default SelectCountryScreen;

  const styles = StyleSheet.create({
    container: {
      flex: 1,
      padding: 20,
    },
    dropdown: {
      height: 50,
      borderBottomColor: 'gray',
      borderBottomWidth: 0.5,
      marginTop: 20,
    },
    selectedText: {
      marginLeft: 8,
    },
  });

SelectCountry example 2

  import React, { useState } from 'react';
  import { StyleSheet, View } from 'react-native';
  import { SelectCountry } from 'react-native-element-dropdown';

  const local_data = [
    {
      value: '1',
      lable: 'Country 1',
      image: {
        uri: 'https://www.vigcenter.com/public/all/images/default-image.jpg',
      },
    },
    {
      value: '2',
      lable: 'Country 2',
      image: {
        uri: 'https://www.vigcenter.com/public/all/images/default-image.jpg',
      },
    },
    {
      value: '3',
      lable: 'Country 3',
      image: {
        uri: 'https://www.vigcenter.com/public/all/images/default-image.jpg',
      },
    },
    {
      value: '4',
      lable: 'Country 4',
      image: {
        uri: 'https://www.vigcenter.com/public/all/images/default-image.jpg',
      },
    },
    {
      value: '5',
      lable: 'Country 5',
      image: {
        uri: 'https://www.vigcenter.com/public/all/images/default-image.jpg',
      },
    },
  ];

  export interface Props {}

  const SelectCountryScreen: React.FC<Props> = _props => {
    const [country, setCountry] = useState('1');

    return (
      <View style={styles.container}>
        <SelectCountry
          style={styles.dropdown}
          selectedTextStyle={styles.selectedText}
          imageStyle={styles.image}
          maxHeight={200}
          search={false}
          value={country}
          data={local_data}
          valueField="value"
          labelField="lable"
          imageField="image"
          placeholder="Select country"
          searchPlaceholder="Search..."
          onChange={e => {
            setCountry(e.value);
          }}
        />
      </View>
    );
  };

  export default SelectCountryScreen;

  const styles = StyleSheet.create({
    container: {
      flex: 1,
      padding: 20,
    },
    dropdown: {
      height: 50,
      width: 160,
      backgroundColor: 'white',
      borderRadius: 22,
      paddingHorizontal: 8,
    },
    selectedText: {
      marginLeft: 8,
      fontSize: 16,
    },
    image: {
      borderRadius: 16,
      width: 32,
      height: 32,
    },
  });

Keywords

FAQs

Package last updated on 22 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc