Skip to content
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
20 changes: 14 additions & 6 deletions src/Select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -890,12 +890,20 @@ export default class Select extends React.Component {
);
if (inputValue) {
const notFindInputItem = sel.every(option => {
return !this.filterOption.call(
this,
inputValue,
option,
() => getValuePropValue(option) === inputValue
);
// this.filterOption return true has two meaning,
// 1, some one exists after filtering
// 2, filterOption is set to false
// condition 2 does not mean the option has same value with inputValue
const filterFn = () => getValuePropValue(option) === inputValue;
if (this.props.filterOption !== false) {
return !this.filterOption.call(
this,
inputValue,
option,
filterFn
);
}
return !filterFn();
});
if (notFindInputItem) {
sel.unshift(
Expand Down
19 changes: 19 additions & 0 deletions tests/Select.tags.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,23 @@ describe('Select.tags', () => {

expect(wrapper).toMatchSnapshot();
});

it('filterOption is false', () => {
const wrapper = mount(
<Select
tags
filterOption={false}
>
<Option value="1">1</Option>
<Option value="2">2</Option>
</Select>,
);
const input = wrapper.find('input');
input.node.focus = jest.fn();
input
.simulate('change', { target: { value: 'a' } })
.simulate('keyDown', { keyCode: KeyCode.ENTER });

expect(wrapper.state().value).toEqual([{ key: 'a', label: 'a', title: undefined }]);
});
});