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.4.3
  • 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

RN Version < 0.60

    react-native link react-native-element-dropdown

Run IOS

    pod install
    react-native run-ios

Run Android

    react-native run-android
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
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
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

Usage

    import React, {useState} from 'react';
    import {StyleSheet, View, Text, Image} from 'react-native';
    import {Dropdown, MultiSelect} from 'react-native-element-dropdown';

    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 DropdownScreen = _props => {
        const [dropdown, setDropdown] = useState(null);
        const [selected, setSelected] = useState([]);

        const _renderItem = item => {
            return (
            <View style={styles.item}>
                <Text style={styles.textItem}>{item.label}</Text>
                <Image style={styles.icon} source={require('./assets/tick.png')} />
            </View>
            );
        };

        return (
            <View style={styles.container}>
                <Dropdown
                    style={styles.dropdown}
                    data={data}
                    search
                    searchPlaceholder="Search"
                    labelField="label"
                    valueField="value"
                    placeholder="Select item"
                    value={dropdown}
                    onChange={item => {
                    setDropdown(item.value);
                        console.log('selected', item);
                    }}
                    renderLeftIcon={() => (
                        <Image style={styles.icon} source={require('./assets/account.png')} />
                    )}
                    renderItem={item => _renderItem(item)}
                />

                <MultiSelect
                    style={styles.dropdown2}
                    data={data}
                    labelField="label"
                    valueField="value"
                    placeholder="Select item"
                    search
                    searchPlaceholder="Search"
                    value={selected}
                    onChange={item => {
                    setSelected(item);
                        console.log('selected', item);
                    }}
                    renderItem={item => _renderItem(item)}
                />
            </View>
        );
    };

    export default DropdownScreen;

    const styles = StyleSheet.create({
        container: {
            flex: 1,
            backgroundColor: 'white',
            padding: 40,
        },
        dropdown: {
            backgroundColor: 'white',
            borderBottomColor: 'gray',
            borderBottomWidth: 0.5,
            marginTop: 20,
        },
        dropdown2: {
            backgroundColor: 'white',
            borderColor: 'gray',
            borderWidth: 0.5,
            marginTop: 20,
            padding: 8,
        },
        icon: {
            marginRight: 5,
            width: 18,
            height: 18,
        },
        item: {
            paddingVertical: 17,
            paddingHorizontal: 4,
            flexDirection: 'row',
            justifyContent: 'space-between',
            alignItems: 'center',
        },
        textItem: {
            flex: 1,
            fontSize: 16,
        },
    });

Keywords

FAQs

Package last updated on 21 Oct 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