JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 309
  • Score
    100M100P100Q81762F
  • License ISC

Auto Complete React component

Package Exports

  • react-autocomplete-select

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-autocomplete-select) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

react-autocomplete-select

Travis npm package Coveralls

React Autocomplete for input field, all styles are fully customizable. In which you coould modify or customize the options JSX and any of the css you want.

Instalation & Configuration

npm install --save react-autocomplete-select


and after installation , Import this package where you want to use the calendar...

import Autocomplete from "react-autocomplete-select";

Use it in this way...

import React, {Component} from 'react';

import Autocomplete from 'react-autocomplete-select'

class Example extends Component {

 inputRef = React.createRef();

 state = {
   changedValue : ''
 }

 componentDidMount(){

   this.inputRef.current.focus();
 }

 componentDidUpdate(){
   // get input field value
   // console.log(this.inputRef.current.value);
 }


 render() {    
   return <div>
     <h3>Autocomplete Demo</h3>
    
       <Autocomplete 

         ref={this.inputRef} // input field's ref prop
         
         searchPattern={'containsString'} // possible values are
         // ['containsString','containsLetter','startsWith','endsWith']
         
         selectOnBlur = {false}    // whether active dropdown option should 
         // select or not when input field is blured
         
         placeholder = "Type to Search" // input field's placeholder
         
         maxOptionsLimit = {10} // max options to show in dropdown
         
         searchEnabled = {true} /** if axiosConfig prop is passed 
         //then itemsData prop is ignored. 
         // And shows the data as returned by the axios request 
         // and does not make the search on the response data of axios request.
         // If you want to enable search on the axios response data 
         // then set searchEnabled = {true}
         **/
         
         getItemValue={(item)=>{ return item.name }} /** get the value from 
         // every element of array passed object 
         // e.g if data to make search on is this 
         // [{country: 'USA'},{country: 'UK'}] 
         // then you will set this props just like this 
         // getItemValue={(item)=>{ return item.country }}
         **/
       
       
       optionsJSX = { (value)=><span>value</span>} // // custom option JSX ...
       // you can enclose the passed value in any valid jsx tags... 
       
         onChange = {
                       changedValue=>{ 
                       this.setState({ changedValue: changedValue }); 
                   }} // called every time the input values get changes
                   
         onSelect = {
                       selectedValue => { 
                       console.log(' so here comes 
                       the selected vlaue ......',selectedValue)
                       }} // called when an option is selected
                       
         axiosConfig = {(inputFieldValue) => ({
           url : 'http://local.cuddlynest.com/autocomplete.php?
           query=${inputFieldValue}',
           method : 'get' // default,
           responseType : 'JSON' // enable this option otherwise will not 
                                   // work properly and response from the 
                                   // server should return the data 
                                   // in json format
           
         }) } // you could pass any of the axios config ... 
              // check axios config docs on this url
              // https://github.com/axios/axios#request-config
              
          
         itemsData = {[ 
                       {
                         "country": "United State"
                       },
                       {
                         "country": "United Kingdom"
                       },
                       {
                       },
                         "country": "Canada"
                       {
                         "country": "Australia"
                       },
                       {
                         "country": "New Zealand"
                       }
                     ]}
       />
   </div>
 }
}

Functional Guide

Property Name Description Type Short Example
onSelect this method is called, when user selects the option from the dropdown function <Autocomplete onSelect= (selectedValue) => { // do whatever you want to do }
onChange called whenever input value changes Array <Autocomplete onChange= (changedValue) => { // do whatever you want to do }
itemsData data from which we will make search when user will type something in the input field Array<Object,Object> <Autocomplete itemsData= [ {country:'USA',country:'UK'} ] />
axiosConfig If you provide axiosConfig data then itemsData will be ignored function:Object <Autocomplete axiosConfig= {inputValue => ({ url: http://locahost/yourfile.php?query=${inputValue}` // you can provide here any of axios config parameters }) }`
getItemValue getItemValue method returns the value that we will use to search and show in the dropdown options function:Any <Autocomplete getItemValue={(item)=>{ return item.name }}
selectOnBlur selectOnBlur decides whether to select the active option or not when input is blured boolean <Autocomplete selectOnBlur = {false} />
searchPattern searchPattern decides the method of search string< startsWith, endsWith, containsString, containsLetter> `<Autocomplete
placeholder placeholder for input field string <Autocomplete placeholder = "Type to Search" />
ref you can pass the ref prop to handle the input field like focus etc etc Object<React.createRef> <Autocomplete ref={this.inputRef} />
optionsJSX you can make the option customized as you want by writing any valid JSX function <Autocomplete optionsJSX = { (value)=><span>value</span>} />
maxOptionsLimit if we got thousands of records in our response or we have passed it in itemsData prop then we could limitize the data to be shown up to an extent e.g 10 number <Autocomplete maxOptionsLimit = { 10 } />
searchEnabled enable search on axios responded data boolean <Autocomplete searchEnabled = {true} />

Style Guide

globalStyle : String
Default Value :
* {
  box-sizing: border-box;
}

body {
  font: 16px Arial;  
}

/*the container must be positioned relative:*/
.autocomplete {
  position: relative;
  display: inline-block;
  width:300px;
}

input {
  border: 1px solid transparent;
  background-color: #f1f1f1;
  padding: 10px;
  font-size: 16px;
}

input[type=text] {
  background-color: #f1f1f1;
  width: 100%;
}


/*Dropdown options container css*/
.___optionsDiv___ {

    position: absolute;
    border: 1px solid #d4d4d4;
    border-bottom: none;
    border-top: none;
    z-index: 99;
    /*position the autocomplete items to be the same width as the container:*/
    top: 100%;
    left: 0;
    right: 0;
}


/*Dropdown options each div css*/
.___optionsDiv___ div {
  padding: 10px;
  cursor: pointer;
  background-color: #fff; 
  border-bottom: 1px solid #d4d4d4; 
}

/*Dropdown options each div on hover css*/

.___optionsDiv___ div:hover {
    background-color: #e9e9e9; 
}


/*when navigating through the items using the arrow keys:*/
.autocomplete-active {
  background-color: DodgerBlue !important; 
  color: #ffffff; 
}
Description :
    you could modify or override any of the above default provided css....