Skip to content

Commit

Permalink
Merge pull request JedWatson#1289 from DanielHeath/clear-async-after-…
Browse files Browse the repository at this point in the history
…selection

Clear Async options after making a selection
  • Loading branch information
JedWatson authored Oct 12, 2016
2 parents cf0429b + a7782b3 commit 47ff3a8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Async.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export default class Async extends Component {
});
}

clearOptions() {
this.setState({ options: [] });
}

loadOptions (inputValue) {
const { cache, loadOptions } = this.props;

Expand Down Expand Up @@ -174,7 +178,13 @@ export default class Async extends Component {
noResultsText: this.noResultsText(),
placeholder: isLoading ? loadingPlaceholder : placeholder,
options: (isLoading && loadingPlaceholder) ? [] : options,
ref: (ref) => (this.select = ref)
ref: (ref) => (this.select = ref),
onChange: (newValues) => {
if (this.props.value && (newValues.length > this.props.value.length)) {
this.clearOptions();
}
this.props.onChange(newValues);
}
};

return children({
Expand Down

0 comments on commit 47ff3a8

Please sign in to comment.