Skip to content

Commit

Permalink
Only remove options if a loading placeholder is available
Browse files Browse the repository at this point in the history
Currently, when `isLoading` is set to true, the options array
is set to an empty array and we show the loading placeholder instead.

Our app has an async service which responds in a couple of ms,
resulting in the autocomplete list flickering in and out of existence
as you type.

This change allows users to opt out of the 'clear options while loading'
behavior by not providing a loading placeholder.
  • Loading branch information
DanielHeath committed Oct 9, 2016
1 parent c40fea0 commit 45be8b4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Async.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const propTypes = {
children: React.PropTypes.func.isRequired, // Child function responsible for creating the inner Select component; (props: Object): PropTypes.element
ignoreAccents: React.PropTypes.bool, // strip diacritics when filtering; defaults to true
ignoreCase: React.PropTypes.bool, // perform case-insensitive filtering; defaults to true
loadingPlaceholder: React.PropTypes.oneOfType([ // replaces the placeholder while options are loading
loadingPlaceholder: React.PropTypes.oneOfType([ // replaces the placeholder while options are loading
React.PropTypes.string,
React.PropTypes.node
]),
Expand Down Expand Up @@ -146,7 +146,7 @@ export default class Async extends Component {
const props = {
noResultsText: isLoading ? loadingPlaceholder : searchPromptText,
placeholder: isLoading ? loadingPlaceholder : placeholder,
options: isLoading ? [] : options,
options: (isLoading && loadingPlaceholder) ? [] : options,
ref: (ref) => (this.select = ref)
};

Expand Down

0 comments on commit 45be8b4

Please sign in to comment.