Skip to content

Commit

Permalink
Added check for invalid filterOptions return value to Creatable
Browse files Browse the repository at this point in the history
  • Loading branch information
bvaughn committed Sep 13, 2016
1 parent d09a267 commit 051bf7d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Creatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const Creatable = React.createClass({
// This covers async edge-cases where a newly-created Option isn't yet in the async-loaded array.
const excludeOptions = params[2] || [];

const filteredOptions = filterOptions(...params);
const filteredOptions = filterOptions(...params) || [];

if (isValidNewOption({ label: this.inputValue })) {
const { newOptionCreator } = this.props;
Expand Down
7 changes: 7 additions & 0 deletions test/Creatable-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ describe('Creatable', () => {
expect(values, 'to contain', 'three');
});

it('should guard against invalid values returned by filterOptions', () => {
createControl({
filterOptions: () => null
});
typeSearchText('test');;
});

it('should not show a "create..." prompt if current filter text is not a valid option (as determined by :isValidNewOption prop)', () => {
createControl({
isValidNewOption: () => false
Expand Down

0 comments on commit 051bf7d

Please sign in to comment.