Simple multi-select component for react-native (Select2 for react-native).
$ npm install react-native-multiple-select --save
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 component
import MultiSelect from 'react-native-multiple-select';
let items = [{
id: '92iijs7yta',
name: 'First Item'
}, {
id: 'a0s0a8ssbsd',
name: 'Second Item'
}, {
id: '16hbajsabsd',
name: 'Third Item'
}, {
id: 'nahs75a5sg',
name: 'Fourth Item'
}, {
id: '667atsas',
name: 'Fifth Item'
}];
let selectedItem = selectedItems => {
// do something with selectedItems
console.log(selectedItems);
};
<MultiSelect
items={items}
uniqueKey="_id"
selectedItemsChange={selectedItem}
selectedItems={[]}
selectText="Pick Items (Selected)"
searchInputPlaceholderText="Search Items..."
fontFamily="ProximaNova-Regular"
altFontFamily="ProximaNova-Light"
tagRemoveIconColor="#000FFF"
tagBorderColor="#CCC"
tagTextColor="#CCC"
selectedItemFontFamily="ProximaNova-Semibold"
selectedItemTextColor="#CCC"
selectedItemIconColor="#CCC"
itemFontFamily="ProximaNova-Regular"
itemTextColor="#000"
searchInputStyle={{fontFamily: 'ProximaNova-Regular', color: '#CCC'}} />
The component takes 3 compulsory props - items
, uniqueKey
and selectedItemsChange
. Other props are optional. The table below explains more.
Prop | Required | Purpose |
---|---|---|
items | Yes | 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) |
uniqueKey | Yes | Unique identifier that is part of each item's properties. Used internally as means of identifying each item (Check sample below) |
selectedItemsChange | Yes | JavaScript function passed in as an argument. The function is to be defined with an argument (selectedItems). The function is called whenever items are added or removed in the component. (Check sample above) |
selectedItems | No | List of selected items. JavaScript Array of objects that is part of the items (check above), that cna be instantiated with the component |
selectText | No | Text displayed in main component |
searchInputPlaceholderText | No | Placeholder text displayed in multi-select filter input |
fontFamily | No | Custom font family to be used in component (affects all text except searchInputPlaceholderText described above) |
altFontFamily | No | Font family for searchInputPlaceholderText |
tagRemoveIconColor | No | Color to be used for the remove icon in selected items list |
tagBorderColor | No | Border color for each selected item |
tagTextColor | No | Text color for selected items list |
selectedItemFontFamily | No | Font family for each selected item in multi-select drop-down |
selectedItemTextColor | No | Text color for each selected item in multi-select drop-down |
selectedItemIconColor | No | Color for selected check icon for each selected item in multi-select drop-down |
itemFontFamily | No | Font family for each non-selected item in multi-select drop-down |
itemTextColor | No | Text color for each non-selected item in multi-select drop-down |
searchInputStyle | No | Style object for multi-select input element |
Contributions are welcome and will be fully credited.
Contributions are accepted via Pull Requests on Github.
-
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.
Check issues for current issues.
The MIT License (MIT). Please see LICENSE for more information.