1.0.0 • Published 4 years ago

react-weblineindia-dropdown v1.0.0

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

ReactJS - Dropdown Component

ReactJS Dropdown Component is a feature rich select / dropdown / typeahead component. It provides a default template that fits most use cases for a filterable select dropdown.

  • configurable via props
  • total custom components overrides for all internals via render prop callbacks (with access to internal props, state and methods)
  • stylable via css (or custom components)
  • portal support for rendering dropdown outside local DOM tree. e.g. in document.body
  • auto position
  • small bundle size

Table of contents

Browser Support

ChromeFirefoxSafariEdgeIE
83.0 ✔77.0 ✔13.1.1 ✔83.0 ✔11.9 ✔

Demo

npm.io

Getting started

npm install react-weblineindia-dropdown
# oR
yarn add react-weblineindia-dropdown

Then, import and register the component:

import React, { Component } from "react";
import Select from 'react-weblineindia-dropdown'
class Test extends Component {
constructor(props) {
    super(props);
    this.state = {
      gender : [
        { name: "abc", id: "1" },
        { name: "pqr", id: "2" },
        { name: "xyz", id: "3"}
    }
  render(){
    retrun(
      <div>
      <Select options={options} onChange={(values) => this.setValues(values)} />
      </div>
    )
  }
}
export default Test

Available Props

PropTypeDefaultDescription
valuesarray[]Selected values
optionsarray[]Available options, (option with key disabled: true will be disabled)
keepOpenboolfalseIf true, dropdown will always stay open (good for debugging)
autoFocusboolfalseIf true, and searchable, dropdown will auto focus
clearOnBlurbooltrueIf true, and searchable, search value will be cleared on blur
clearOnSelectbooltrueIf true, and searchable, search value will be cleared upon value select/de-select
namestringnullIf set, input type hidden would be added in the component with the value of the name prop as name and select's values as value
requiredboolfalseIf set, input type hidden would be added in the component with required prop as true/false
patternstringnullIf set, input type hidden would be added in the component with pattern prop as regex
dropdownGapnumber5Gap between select element and dropdown
placeholderstring"Select..."Placeholder shown where there are no selected values
addPlaceholderstring""Secondary placeholder on search field if any value selected
disabledboolfalseDisable select and all interactions
styleobject{}Style object to pass to select
classNamestringCSS class attribute to pass to select
loadingboolfalseLoading indicator
clearableboolfalseClear all indicator
searchablebooltrueIf true, select will have search input text
separatorboolfalseSeparator line between close all and dropdown handle
dropdownHandlebooltrueDropdown handle to open/close dropdown
dropdownHeightstring"300px"Minimum height of a dropdown
directionstring"ltr"direction of a dropdown "ltr", "rtl" or "auto"
searchBystringlabelSearch by object property in values
sortBystringnullSort by object property in values
labelFieldstring"label"Field in data to use for label
valueFieldstring"value"Field in data to use for value
colorstring"#0074D9"Base color to use in component, also can be overwritten via CSS
closeOnScrollboolfalseIf true, scrolling the page will close the dropdown
closeOnSelectboolfalseIf true, selecting option will close the dropdown
dropdownPositionstring"bottom"Available options are "auto", "top" and "bottom" defaults to "bottom". Auto will adjust itself according Select's position on the page
keepSelectedInListbooltrueIf false, selected item will not appear in a list
portalDOM elementfalseIf valid dom element specified - dropdown will break out to render inside the specified element
createboolfalseIf true, select will create value from search string and fire onCreateNew callback prop
backspaceDeletebooltrueIf true, backspace key will delete last value
createNewLabelstring"add {search}"If create set to true, this will be the label of the "add new" component. {search} will be replaced by search value
disabledLabelstring"disabled"Label shown on disabled field (after) the text
additionalPropsobjectnull

Events

PropTypeDefaultDescription
onChangefuncOn values change callback, returns array of values objects
onDropdownClosefuncFires upon dropdown close
onDropdownOpenfuncFires upon dropdown open
onCreateNewfuncFires upon creation of new item if create prop set to true
onClearAllfuncFires upon clearing all values (via custom renderers)
onSelectAllfuncFires upon selecting all values (via custom renderers)
onDropdownCloseRequestfuncundefinedFires upon dropdown closing state, stops the closing and provides own method close()
contentRendererfuncOverrides internal content component (the contents of the select component)
itemRendererfuncOverrides internal item in a dropdown
noDataRendererfuncOverrides internal "no data" (shown where search has no results)
optionRendererfuncOverrides internal option (the pillow with an "x") on the select content
inputRendererfuncOverrides internal input text
loadingRendererfuncOverrides internal loading
clearRendererfuncOverrides internal clear button
separatorRendererfuncOverrides internal separator
dropdownRendererfuncOverrides internal dropdown component
dropdownHandleRendererfuncOverrides internal dropdown handle
searchFnfuncundefinedOverrides internal search function
handleKeyDownFnfuncundefinedOverrides internal keyDown function

Want to Contribute?

  • Created something awesome, made this code better, added some functionality, or whatever (this is the hardest part).
  • Fork it.
  • Create new branch to contribute your changes.
  • Commit all your changes to your branch.
  • Submit a pull request.

Collection of Components

We have built many other components and free resources for software development in various programming languages. Kindly click here to view our Free Resources for Software Development.


Changelog

Detailed changes for each release are documented in CHANGELOG.md.

Credits

react-weblineindia-dropdown is inspired by react-dropdown-select.

License

MIT

Keywords

react-weblineindia-dropdown, react-dropdown, reactjs-dropdown, dropdown-component, react-select, reactjs-select