1.0.0 • Published 4 years ago

react-dadata-suggestions-fork v1.0.0

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

react-dadata-suggestions

Just another one React component for dadata suggestions.

Getting started

Installation

npm i --save react-dadata-suggestions

page on npm

Basic usage

Examples on sandbox

import React, { Component } from 'react';
import DadataSuggestions from 'react-dadata-suggestions';
import "react-dadata-suggestions/dist/styles.css";

const token = 'your_token';

class App extends Component {
  render() {
    return (
      <DadataSuggestions
        token={ token }
        onSelect={ (suggestion) => console.log(suggestion) }
      />
    );
  }
}

export default App;

Available props

Options

proptypedescriptionrequireddefault
tokenstringapi tokentrue''
countintegermaximal suggestions count in listfalse10
deferRequestByintegerdelay in milliseconds before each requestfalse300
placeholderstringfalse''
hintstringhint for user in suggestions listfalseВыберите вариант ниже или продолжите ввод
minCharsintegerminimal length of query for requesting to apifalse3
geolocationbooleanpriority to user city. Works for address suggestions only.falsetrue
servicestringavailable values: address, bank, fio, email and party (I don't know why, but api for searching of the companies is called "party")falseaddress
highlightingboolhighlight matched words in suggestionsfalsetrue
receivePropsBehaveLikeOnChangeboolsee belowfalsefalse
valueobjectsuggestion itemfalsenull
namestringinput namefalsenull
readOnlymark field as readonlyfalse
disabledmark field as disabledfalse
suggestionsFormatter (suggestion)functioncustom formatter for items in suggestions listfalse
selectedSuggestionFormatter (suggestion)functionthe same as previous for selected suggestion (result will be placed in query string)false
specialRequestOptionsobjectadditional data for request bodyfalse
onSelect (suggestion)functionbe called when user select the address from suggestionstrue
onChange (query)functionbe called when user typing something in input fieldfalse
onError (error)functionwill be called if api request failedfalse
onBlurfunctionwill be called on focus outfalse
onFocusfunctionwill be called on focus eventfalse

The structure of suggestion object can be found in official dadata api documentation

  • receivePropsBehaveLikeOnChange - change the behavior of componentWillReceiveProps life-cycle hook. By default this handler just resets the state of component. If this prop is set to true componentWillReceiveProps will behave exactly like onChange handler do. Probably it must be the only behavior, but the first implementation was keeped as default for backward compability reasons.

Highlighting

Override class .suggestions-highlighting in your CSS to customize highlighting.

License

This project is licensed under the MIT License