From 361342a34a4eb78966c89c88a19a2714f774d4aa Mon Sep 17 00:00:00 2001 From: Wei Zhu Date: Tue, 28 Feb 2017 16:23:29 +0800 Subject: [PATCH] Fire search event only when inputValue changes --- src/Select.jsx | 12 +++++++----- tests/Select.spec.js | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/Select.jsx b/src/Select.jsx index 0ab5a02b9..2e936b481 100644 --- a/src/Select.jsx +++ b/src/Select.jsx @@ -572,11 +572,13 @@ const Select = React.createClass({ }); }, setInputValue(inputValue, fireSearch = true) { - this.setState({ - inputValue, - }); - if (fireSearch) { - this.props.onSearch(inputValue); + if (inputValue !== this.state.inputValue) { + this.setState({ + inputValue, + }); + if (fireSearch) { + this.props.onSearch(inputValue); + } } }, clearBlurTime() { diff --git a/tests/Select.spec.js b/tests/Select.spec.js index bc9aa5ac5..f4a7b9078 100644 --- a/tests/Select.spec.js +++ b/tests/Select.spec.js @@ -241,6 +241,23 @@ describe('Select', () => { expect(handleSearch).toBeCalledWith('1'); }); + it('not fires search event when user select', () => { + const handleSearch = jest.fn(); + const wrapper = mount( + + ); + wrapper.find('.rc-select').simulate('click'); + const dropdownWrapper = mount(wrapper.find('Trigger').node.getComponent()); + dropdownWrapper.find('MenuItem').first().simulate('click'); + expect(handleSearch).not.toBeCalled(); + }); + describe('focus', () => { let handleFocus; let wrapper;