1.3.11 • Published 1 year ago

react-bootstrap-select-dropdown v1.3.11

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

react-bootstrap-select-dropdown

A custom Bootstrap select / multiselect using dropdown button, designed to behave like regular select form control. Bootstrap Select/Multiselect developed to use with React 16+ and Bootstrap 4.

Installation

npm i react-bootstrap-select-dropdown --save

Usage

Quick Usage

Import BootstrapSelect component

import BootstrapSelect from 'react-bootstrap-select-dropdown';

Use of component

<BootstrapSelect options={options} />

Required JSON to list {options}

"options": [
	{
		"labelKey": "optionItem1",
		"value": "Option item 1"
	},
	{
		"labelKey": "optionItem2",
		"value": "Option item 2"
	}
]

Use of callback function

const handleChange = (selectedOptions) => {
	console.log(selectedOptions);
}

<BootstrapSelect options={options} onChange={handleChange} />

Optional key support in {options} JSON

KeyTypeDefaultDescription
isSelectedbooleanIt is used to set option selected default on component load.
isDisabledbooleanIt is used to set option disabled and user will unable to select.
iconstringClass name of an icon to show before option text. You can define multiple classes with icon class.
classNamestringAdd custom class to each option
stylestyle JSONAdd custom style attr to each option
"options": [
	{
		"labelKey": "optionItem1",  // Required
		"value": "Option item 1", // Required
		"isSelected": true, // Optional
		"isDisabled": false,  // Optional
		"icon": "icon-class-name" //Optional
		"className": "custom-class-name" //Optional
		"style": { //Optional
			"backgroundColor":"#000000",
			"color": "#FFFFFF"
		}
	}
]

Props support in BootstrapSelect

PropTypeDefaultDescription
optionsarrayAn array of option's objects to list in dropdown menu
defaultOptionsarrayIt's allow to set default option(s) manually on load even if "isSelected" is not set in option's object. Array item(s) must contain value same as "labelKey" of options.
isMultiSelectbooleanfalseAllow to select multiple options.
showTickbooleanfalseTo display tick with option on select.
showSearchbooleanfalseAllow to search from options list.
showActionbooleanfalseEnable actions buttons select/deselect all options, will work only if isMultiSelect sets to true.
disabledbooleanfalseIt's allow you disable boostrap select on component load
selectStylestringbtn-lightApply custom style by using custom class or bootstrap btn style classes.
actionBtnStylestringbtn-outline-darkApply custom style to action buttons (select/deselect all) by using custom class or bootstrap btn style classes. Will work only if isMultiSelect sets to true.
menuSize'auto'/false/number'auto'Allows to set max. options to list with vertical scrollbar if many options.
showCountOnnumberShow selected options number as selected value in select.
classNamestringAdd classes to outer most tag.
placeholderstringNo option selectedSet custom placeholder if no option selected.
onChangefunctionAn onChange handler passed to the Toggle component
onClosefunctionAn onClose handler passed to the Toggle component

Dependencies

Make sure Bootstrap 4 is installed in you project or required to install it and css needs to imported in project:

Installation bootstrap

npm install bootstrap@4.6.0

Import bootstrap css

import 'bootstrap/dist/css/bootstrap.min.css';