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

react-native-multiple-select-expo

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-multiple-select-expo

Simple multi-select component for react-native expo

  • 0.4.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
decreased by-53.85%
Maintainers
1
Weekly downloads
 
Created
Source

react-native-multiple-select-expo

npm Downloads Licence

Simple multi-select component for react-native (Select2 for react-native).

multiple single

Important notice

All credit goes to the original author of this package. This fork was created to support expo vector icons. If you'd like to reach out to original author you can find him here: email. I am not working on this project actively, it was an effort to solve a very small problem in a minimalistic fashion. Perhaps this project will later on veer a bit more from the original

Installation

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

or use yarn

$ yarn add react-native-multiple-select

Usage

Note: Ensure to add and configure @expo/vector-icons

The snippet below shows how the component can be used

// import component
import React, { Component } from 'react';
import { View } from 'react-native';
import MultiSelect from 'react-native-multiple-select';

class MultiSelectExample extends Component {

  this.state = {
    selectedItems = [];
  };

  this.items = [{
    id: '92iijs7yta',
    name: 'Ondo',
  }, {
    id: 'a0s0a8ssbsd',
    name: 'Ogun',
  }, {
    id: '16hbajsabsd',
    name: 'Calabar',
  }, {
    id: 'nahs75a5sg',
    name: 'Lagos',
  }, {
    id: '667atsas',
    name: 'Maiduguri',
  }, {
    id: 'hsyasajs',
    name: 'Anambra',
  }, {
    id: 'djsjudksjd',
    name: 'Benue',
  }, {
    id: 'sdhyaysdj',
    name: 'Kaduna',
  }, {
    id: 'suudydjsjd',
    name: 'Abuja',
  }];

  onSelectedItemsChange = selectedItems => {
    this.setState({ selectedItems });
  };

  render() {
    const { selectedItems } = this.state;
    return (
      <View style={{ flex: 1 }}>
        <MultiSelect
          hideTags
          items={items}
          uniqueKey="id"
          ref={(component) => { this.multiSelect = component }}
          onSelectedItemsChange={this.onSelectedItemsChange}
          selectedItems={selectedItems}
          selectText="Pick Items"
          searchInputPlaceholderText="Search Items..."
          onChangeInput={ (text)=> console.log(text)}
          altFontFamily="ProximaNova-Light"
          tagRemoveIconColor="#CCC"
          tagBorderColor="#CCC"
          tagTextColor="#CCC"
          selectedItemTextColor="#CCC"
          selectedItemIconColor="#CCC"
          itemTextColor="#000"
          displayKey="name"
          searchInputStyle={{ color: '#CCC' }}
          submitButtonColor="#CCC"
          submitButtonText="Submit"
        />
        <View>
          {this.multiSelect.getSelectedItemsExt(selectedItems)}
        </View>
      </View>
    );
  }
}

The component takes 3 compulsory props - items, uniqueKey and onSelectedItemsChange. Other props are optional. The table below explains more.

Props

PropRequiredPurpose
altFontFamilyNo(String) Font family for searchInputPlaceholderText
canAddItemsNo(Boolean) Defaults to "false". This allows a user to add items to the list of items provided. You need to handle adding the new items in the onAddItem function prop. Items may be added with the return key on the native keyboard.
displayKeyNo(String) Defaults to "name". This string will be used to select the key to display the objects in the items array
fixedHeightNo(Boolean) Defaults to false. Specifies if select dropdown take height of content or a fixed height with a scrollBar (There is an issue with this behavior when component is nested in a ScrollView in which scroll event will only be dispatched to parent ScrollView and select component won't be scrollable). See this issue for more info.
flatListPropsNo(Object) Properties for the FlatList. Pass any property that is required on the FlatList of the dropdown menu
fontFamilyNo(String) Custom font family to be used in component (affects all text except searchInputPlaceholderText described above)
fontSizeNo(Number) Font size for selected item name displayed as label for multiselect
hideDropdownNo(Boolean) Defaults false. Hide dropdown menu with a cancel, and use arrow-back
hideSubmitButtonNo(Boolean) Defaults to false. Hide submit button from dropdown, and rather use arrow-button in search field
hideTagsNo(Boolean) Defaults to false. Hide tokenized selected items, in case selected items are to be shown somewhere else in view (check below for more info)
itemFontFamilyNo(String) Font family for each non-selected item in multi-select drop-down
itemFontSizeNo(Number) Font size used for each item in the multi-select drop-down
itemTextColorNo(String) Text color for each non-selected item in multi-select drop-down
itemsYes(Array, control prop) List of items to display in the multi-select component. JavaScript Array of objects. Each object must contain a name and unique identifier (Check sample above)
onAddItemNo(Function) JavaScript function passed in as an argument. The function is called everythime a new item is added, and receives the entire list of items. Here you should ensure that the new items are added to your provided list of items in addition to any other consequences of new items being added.
onChangeInputNo(Function) JavaScript function passed in as an argument. The function is called everythime TextInput is changed with the value.
onSelectedItemsChangeYes(Function) JavaScript function passed in as an argument. The function is to be defined with an argument (selectedItems). Triggered when Submit button is clicked (for multi select) or item is clicked (for single select). (Check sample above)
searchInputPlaceholderTextNo(String) Placeholder text displayed in multi-select filter input
searchInputStyleNo(Object) Style object for multi-select input element
selectTextNo(String) Text displayed in main component
selectedItemFontFamilyNo(String) Font family for each selected item in multi-select drop-down
selectedItemIconColorNo(String) Color for selected check icon for each selected item in multi-select drop-down
selectedItemTextColorNo(String) Text color for each selected item in multi-select drop-down
singleNo(Boolean) Toggles select component between single option and multi option
styleDropdownMenuNo(Style) Style the view of the dropdown menu
styleDropdownMenuSubsectionNo(Style) Style the inner view of the dropdown menu
styleInputGroupNo(Style) Style the Container of the Text Input Group
styleItemsContainerNo(Style) Style the Container of the items that are displayed in a list
styleMainWrapperNo(Style) Style the Main Container of the MultiSelector
styleRowListNo(Style) Style the Row that is displayed after you
submitButtonColorNo(String) Background color for submit button
submitButtonTextNo(String) Text displayed on submit button
tagBorderColorNo(String) Border color for each selected item
tagRemoveIconColorNo(String) Color to be used for the remove icon in selected items list
tagTextColorNo(String) Text color for selected items list
textColorNo(String) Color for selected item name displayed as label for multiselect
textInputPropsNo(Object) Properties for the Text Input. Pass any property that is required on the text input
uniqueKeyYes(String) Unique identifier that is part of each item's properties. Used internally as means of identifying each item (Check sample below)
selectedItemsNo(Array, control prop) List of selected items keys . JavaScript Array of strings, that can be instantiated with the component

Note

  • Tokenized selected items can be displayed in any other part of the view by adding a ref to the MultiSelect component like so ref={(component) => { this.multiSelect = component }}. Then add this to any part of the screen you want the tokens to show up: this.multiSelect.getSelectedItemsExt(selectedItems). The selectedItems argument passed into the above mentioned method is the same selectedItems passed as the main component selected items prop. (See example above).

  • If users shouldn't be able to select any of the items in the dropdown list, set a disabled key to true in the item. Such item will be rendered in gray and won't be clickable.

  • When using the single prop, selectedItems should still be passed in as an array of selected items keys. Also, when an item is selected in the single mode, the selected item is returned as an array of string.

  • The items props must be passed as an array of objects with a compulsory name key present in each object as the name key is used to display the items in the options component.

Removing all selected items

To use, add ref to MultiSelect component in parent component, then call method against reference. i.e.

<MultiSelect
  ref={c => this._multiSelect = c}
  ...
/>

clearSelectedCategories = () => {
   this._multiSelect._removeAllItems();
};

Contributing

Contributions are welcome and will be fully credited.

Contributions are accepted via Pull Requests on Github.

Pull Requests

  • Document any change in behaviour - Make sure the README.md and any other relevant documentation are kept up-to-date.

  • Consider our release cycle - We try to follow SemVer v2.0.0. Randomly breaking public APIs is not an option.

  • Create feature branches - Don't ask us to pull from your master branch.

  • One pull request per feature - If you want to do more than one thing, send multiple pull requests.

  • Send coherent history - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting.

Issues

Check issues for current issues.

Contributors

Here is list of CONTRIBUTORS

License

The MIT License (MIT). Please see LICENSE for more information.

Keywords

FAQs

Package last updated on 23 Jan 2019

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