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
12 changes: 7 additions & 5 deletions src/Select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
17 changes: 17 additions & 0 deletions tests/Select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<Select
showSearch
onSearch={handleSearch}
>
<Option value="1">1</Option>
<Option value="2">2</Option>
</Select>
);
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;
Expand Down