Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Added check for invalid filterOptions return value to Creatable #1213

Merged
merged 1 commit into from
Sep 13, 2016
Merged
Show file tree
Hide file tree
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
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