Skip to content

Commit

Permalink
Add queryDelay parameter to Geosuggest, defaulted to 250ms.
Browse files Browse the repository at this point in the history
  • Loading branch information
lsanwick committed Jun 9, 2016
1 parent 8eceb63 commit 9daff3a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/Geosuggest.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import React from 'react';
import classnames from 'classnames';
import debounce from 'lodash.debounce';

import defaults from './defaults';
import propTypes from './prop-types';
Expand Down Expand Up @@ -32,6 +33,14 @@ class Geosuggest extends React.Component {
suggests: [],
timer: null
};

this.onInputChange = this.onInputChange.bind(this);
this.onAfterInputChange = this.onAfterInputChange.bind(this);

if (props.queryDelay) {
this.onAfterInputChange =
debounce(this.onAfterInputChange, props.queryDelay);
}
}

/**
Expand Down Expand Up @@ -78,10 +87,12 @@ class Geosuggest extends React.Component {
* @param {String} userInput The input value of the user
*/
onInputChange(userInput) {
this.setState({userInput}, () => {
this.showSuggests();
this.props.onChange(userInput);
});
this.setState({userInput}, this.onAfterInputChange);
}

onAfterInputChange() {
this.showSuggests();
this.props.onChange(this.state.userInput);
}

/**
Expand Down Expand Up @@ -320,7 +331,7 @@ class Geosuggest extends React.Component {
ref='input'
value={this.state.userInput}
ignoreTab={this.props.ignoreTab}
onChange={this.onInputChange.bind(this)}
onChange={this.onInputChange}
onFocus={this.onInputFocus.bind(this)}
onBlur={this.onInputBlur.bind(this)}
style={this.props.style.input}
Expand Down
1 change: 1 addition & 0 deletions src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default {
bounds: null,
country: null,
types: null,
queryDelay: 250,
googleMaps: null,
onActivateSuggest: () => {},
onSuggestSelect: () => {},
Expand Down
1 change: 1 addition & 0 deletions src/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default {
bounds: React.PropTypes.object,
country: React.PropTypes.string,
types: React.PropTypes.array,
queryDelay: React.PropTypes.number,
googleMaps: React.PropTypes.object,
onSuggestSelect: React.PropTypes.func,
onFocus: React.PropTypes.func,
Expand Down

0 comments on commit 9daff3a

Please sign in to comment.