React Native Element Dropdown

2.12.4 · active · verified Sun Apr 19

React Native Element Dropdown is a versatile library providing highly customizable dropdown and multi-select components for React Native applications. It aims to simplify the creation of selection menus, offering a consistent look and feel across iOS and Android platforms. The current stable version is 2.12.4, with a fairly active release cadence, typically seeing bug fixes and minor feature additions every few months. Key differentiators include built-in support for both single-select dropdowns and multi-select functionality within a single package, extensive customization options for styling (font size, colors, animation duration, 'default', 'modal', or 'auto' display modes), and robust TypeScript support. It also features search capabilities, lazy loading (indicated by keywords), and specific props for controlling item visibility and modal behavior.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic single-select dropdown component, including state management for the selected value, data definition, and essential styling using TypeScript.

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

interface Item { label: string; value: string; }

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

const DropdownComponent: React.FC = () => {
  const [value, setValue] = useState<string | null>(null);

  return (
    <View style={styles.container}>
      <Dropdown
        style={styles.dropdown}
        placeholderStyle={styles.placeholderStyle}
        selectedTextStyle={styles.selectedTextStyle}
        inputSearchStyle={styles.inputSearchStyle}
        iconStyle={styles.iconStyle}
        data={data}
        search
        maxHeight={300}
        labelField="label"
        valueField="value"
        placeholder="Select item"
        searchPlaceholder="Search..."
        value={value}
        onChange={item => {
          setValue(item.value);
        }}
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    backgroundColor: 'white',
    padding: 16,
  },
  dropdown: {
    height: 50,
    borderColor: 'gray',
    borderWidth: 0.5,
    borderRadius: 8,
    paddingHorizontal: 8,
  },
  icon: {
    marginRight: 5,
  },
  placeholderStyle: {
    fontSize: 16,
  },
  selectedTextStyle: {
    fontSize: 16,
  },
  iconStyle: {
    width: 20,
    height: 20,
  },
  inputSearchStyle: {
    height: 40,
    fontSize: 16,
  },
});

export default DropdownComponent;

view raw JSON →