Giter VIP home page Giter VIP logo

multiselect-react-dropdown's Introduction

REACT MULTISELECT DROPDOWN

Version Downloads License PRs Tweet

๐Ÿ’ฅ๐Ÿ’ฅ๐Ÿ’ฅ React Library for Component Lazyloading. Tiny and Efficient. Check it Out ๐Ÿ’ฅ๐Ÿ’ฅ๐Ÿ’ฅ

Description

A React component which provides multi select functionality with various features like selection limit, CSS customization, checkbox, search option, disable preselected values, flat array, keyboard navigation for accessibility and grouping features. Also it has feature to behave like normal dropdown(means single select dropdown).

Multiselect

Getting Started

1. Installation

npm install multiselect-react-dropdown

2. Demo

React-multi-select-dropdown


3. Basic Usage

import { Multiselect } from 'multiselect-react-dropdown';

this.state = {
    options: [{name: 'Srigar', id: 1},{name: 'Sam', id: 2}]
};

<Multiselect
options={this.state.options} // Options to display in the dropdown
selectedValues={this.state.selectedValue} // Preselected value to persist in dropdown
onSelect={this.onSelect} // Function will trigger on select event
onRemove={this.onRemove} // Function will trigger on remove event
displayValue="name" // Property name to display in the dropdown options
/>

onSelect(selectedList, selectedItem) {
    ...
}

onRemove(selectedList, removedItem) {
    ...
}

4. Props

Prop Type Default Description
options array [] Dropdown options
onSelect function func Callback function will invoked on select event. Params are selectedList & selectedItem
onRemove function func Callback function will invoked on remove event. Params are selectedList & removedItem
singleSelect boolean false Make it true to behave like a normal dropdown(single select dropdown)
selectedValues array [] Preselected value to persist in dropdown
showCheckbox bool false To display checkbox option in the dropdown
selectionLimit number -1 You can limit the number of items that can be selected in a dropdown
placeholder string Select Placeholder text
disablePreSelectedValues bool false Prevent to deselect the preselected values
isObject bool true Make it false to display flat array of string or number Ex. ['Test1',1]
displayValue string value Property name in the object to display in the dropdown. Refer Basic Usage section
emptyRecordMsg string No options available Message to display when no records found
groupBy string '' Group the popup list items with the corresponding category by the property name in the object
closeIcon string circle Option to select close icon instead of default. Refer Close Icon section
style object {} CSS Customization for multiselect. Refer below object for css customization.
caseSensitiveSearch bool false Enables case sensitivity on the search field.
closeOnSelect bool true Dropdown get closed on select item.
id string '' Id for the multiselect container and input field(In input field it will append '{id}_input').
avoidHighlightFirstOption bool false Based on flag first option will get highlight whenever optionlist open.

5. Ref as a prop

By using React.createRef() or useRef(), able to access below methods to get or reset selected values

Method Name Description
resetSelectedValues Programatically reset selected values
getSelectedItems Get all selected items
getSelectedItemsCount Get selected items count
constructor() {
  this.multiselectRef = React.createRef();
}

resetValues() {
  // By calling the belowe method will reset the selected values programatically
  this.multiselectRef.current.resetSelectedValues();
}

<Multiselect
options={this.state.options} // Options to display in the dropdown
ref={this.multiselectRef}
/>

6. CSS Customization

{
  multiselectContainer: { // To change css for multiselect (Width,height,etc..)
	....
  },
  searchBox: { // To change search box element look
	border: none;
	font-size: 10px;
	min-height: 50px;
  },
  inputField: { // To change input field position or margin
      margin: 5px;
  },
  chips: { // To change css chips(Selected options)
	background: red;
  },
  optionContainer: { // To change css for option container 
	border: 2px solid;
  }
  option: { // To change css for dropdown options
	color: blue;
  },
  groupHeading: { // To chanage group heading style
	....
  }
}

7. Close Icons

Name Image
circle Close Icon
circle2 Close Icon
cancel Close Icon
close Close Icon

8. Licence

MIT

multiselect-react-dropdown's People

Contributors

dependabot[bot] avatar jmsaucier avatar mrpeker avatar pmpurifoy avatar rfdlp avatar shellylane avatar srigar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.