1.0.7 • Published 4 years ago

react-native-advanced-select v1.0.7

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

react-native-advanced-select

npm version MIT license

Simple select component with in-built search for React-Native.

Demo

Installation

$ npm install react-native-advanced-select --save

or use yarn

$ yarn add react-native-advanced-select

Usage

Note: Ensure to add and configure react-native-vector-icons to your project before using this package.

The snippet below shows how the component can be used

import React from 'react';
import { View, Text } from 'react-native';
import Select from 'react-native-advanced-select';

class SelectExample extends React.Component {
  constructor(props, state) {
    super(props, state);
    this.state = {
      selectedKey: '',
      items: [
        { myKey: 1, myLabel: "Fruits" },
        { myKey: 2, myLabel: "Red Apples" },
        { myKey: 3, myLabel: "Cherries" },
        { myKey: 4, myLabel: "Cranberries" },
        { myKey: 5, myLabel: "Pink Grapefruit" },
        { myKey: 6, myLabel: "Raspberries" },
        { myKey: 7, myLabel: "Vegetables" },
        { myKey: 8, myLabel: "Beets" },
        { myKey: 9, myLabel: "Red Peppers" },
        { myKey: 10, myLabel: "Radishes" },
        { myKey: 11, myLabel: "Radicchio" },
        { myKey: 12, myLabel: "Red Onions" },
        { myKey: 13, myLabel: "Red Potatoes" },
        { myKey: 14, myLabel: "Rhubarb" },
        { myKey: 15, myLabel: "Tomatoes" }
      ]
    };
  }

  onSelectedItemsChange = (item, index) => {
    const key = item.myKey
    this.setState({ selectedKey: key });
  };

  render() {
    const { selectedKey, items } = this.state;
    return (
      <View style={{ flex: 1 }}>
        <Select
          selectedKey={selectedKey}
          data={items}
          width={250}
          placeholder="Select a value ..."
          onSelect={this.onSelectedItemsChange.bind(this)}
          search={true}
          keyExtractor={(item) => item.myKey || ''}
          labelExtractor={(item) => item.myLabel || ''}
        />
      </View>
    );
  }
}

Props

Prop NameProp TypeDefault ValuesDescription
onSelectfunc(item, index) => {}Callback function invoked on option select that takes (selectedOptionItem, selectedOptionindex) as parameters
placeholderstringSelectText to show as default text
searchPlaceholderstringSearchText to show as default search text
styleobject{}To style the select box
optionTextStyleobject{}To style the text shown in the box
optionContainerStyleobject{}To style the options shown
searchboolfalseUse search in Component
selectedKeystring or number""Key of the item which is selected whose label will be displayed
parentScrollEnablefuncnullHack for Android nested ScrollView
parentScrollDisablefuncnullHack for Android nested ScrollView
keyExtractorfunc(item) => item.key || ""Function that extracts the key to uniquely identify an item
labelExtractorfunc(item) => item.label || ""Function that extracts the label to be displayed for an item
disabledboolfalseTo disable dropdown toggle/click
disabledTextStyleobject{ color: 'lightgrey' }To style text displayed when disabled is true
optionNumberOfLinesnumber1To set certain number of lines to text rendered in select value and select options' labels
placeholderTextStyleobject{}To style the placeholder text displayed when no option is selected
showCustomRightIconViewbooleanfalseTo decide if you want to render custom right icon for dropdown or not
customRightIconViewfuncnullTo render custom right icon view in dropdown
selectedRowStyleobject{ backgroundColor: '#D1D1D6FF' }To style the selected option view when dropdown is opened