Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/Chips.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component } from 'react';
import React, { Component, createRef } from 'react';
import PropTypes from 'prop-types';
import Autosuggest from 'react-autosuggest';
import Radium from 'radium';
Expand All @@ -20,20 +20,23 @@ class Chips extends Component {
suggestions: []
};

this.asyncSuggestLimiter =
this.divRef = createRef()
this.asyncSuggestLimiter =
new CallLimiter(this.callFetchSuggestions.bind(this), 1000 / props.fetchSuggestionsThrushold);
}

componentWillReceiveProps = (nextProps) => {
this.asyncSuggestLimiter.interval = (1000 / nextProps.fetchSuggestionsThrushold);
static getDerivedStateFromProps(nextProps, prevState) {
return {
interval: (1000 / nextProps.fetchSuggestionsThrushold)
};
}

onBlur = e => {
this.refs.wrapper.focus();
this.divRef.current.focus();
}

onFocus = e => {
this.refs.wrapper.blur();
this.divRef.current.blur();
}

handleKeyDown = e => {
Expand Down Expand Up @@ -106,17 +109,17 @@ class Chips extends Component {

callFetchSuggestions = (fetchSuggestions, value, canceled) => {
let { uniqueChips } = this.props;

let callback = suggestions => {
if(!canceled.isCancaled()){
this.setState({
this.setState({
loading: false,
suggestions: (uniqueChips ? this.filterUniqueChips(suggestions) : suggestions)
});
}
}

let suggestionResult =
let suggestionResult =
fetchSuggestions.call(this, value, callback);

if(suggestionResult && 'then' in suggestionResult){ // To Support Promises
Expand Down Expand Up @@ -175,7 +178,7 @@ class Chips extends Component {
};

return (
<div {...themr(200, 'chipsContainer')} ref="wrapper" >
<div {...themr(200, 'chipsContainer')} ref={this.divRef} >
{this.renderChips()}
<Autosuggest
{...this.props}
Expand Down