From 285af2a89104b65b5f5a34fd85f258e1757bf690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=89=E5=BC=98?= Date: Mon, 21 Aug 2017 16:45:32 +0800 Subject: [PATCH] fix: lint error --- src/Select.jsx | 20 ++++++++++++++------ tests/Select.tags.spec.js | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/Select.jsx b/src/Select.jsx index 48c143691..d336ce1bb 100644 --- a/src/Select.jsx +++ b/src/Select.jsx @@ -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( diff --git a/tests/Select.tags.spec.js b/tests/Select.tags.spec.js index 8b98e2665..20cc8c79b 100644 --- a/tests/Select.tags.spec.js +++ b/tests/Select.tags.spec.js @@ -92,4 +92,23 @@ describe('Select.tags', () => { expect(wrapper).toMatchSnapshot(); }); + + it('filterOption is false', () => { + const wrapper = mount( + , + ); + 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 }]); + }); });