Skip to content
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ React.render(c, container);
|combobox | enable combobox mode(can not set multiple at the same time) | bool | false |
|multiple | whether multiple select | bool | false |
|disabled | whether disabled select | bool | false |
|triggerOnchange | trigger input onChange event after an option is selected(onSelect) | bool | true |
|filterOption | whether filter options by input value. default filter by option's optionFilterProp prop's value | bool | true/Function(inputValue:string, option:Option) |
|optionFilterProp | which prop value of option will be used for filter if filterOption is true | String | 'value' |
|optionLabelProp | which prop value of option will render as content of select | String | 'value' |
Expand Down
1 change: 1 addition & 0 deletions src/PropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const SelectPropTypes = {
showSearch: PropTypes.bool,
disabled: PropTypes.bool,
allowClear: PropTypes.bool,
triggerOnchange: PropTypes.bool,
showArrow: PropTypes.bool,
tags: PropTypes.bool,
prefixCls: PropTypes.string,
Expand Down
4 changes: 3 additions & 1 deletion src/Select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const Select = React.createClass({
defaultActiveFirstOption: true,
showSearch: true,
allowClear: false,
triggerOnchange: true,
placeholder: '',
onChange: noop,
onFocus: noop,
Expand Down Expand Up @@ -270,8 +271,9 @@ const Select = React.createClass({
this.setOpenState(false, true);
}
this.fireChange(value);

let inputValue;
if (isCombobox(props)) {
if (isCombobox(props) && props.triggerOnchange) {
inputValue = getPropValue(item, props.optionLabelProp);
} else {
inputValue = '';
Expand Down
36 changes: 36 additions & 0 deletions tests/Select.triggerOnchange.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-disable no-undef */
import React from 'react';
import { mount } from 'enzyme';
import Select, { Option } from '../src';

describe('test test test', () => {
it('fires input change by default ', () => {
const wrapper = mount(
<Select combobox>
<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(wrapper.state().inputValue).toBe('1');
});

it('not fires input change when triggerOnchange is false ', () => {
const wrapper = mount(
<Select combobox triggerOnchange={false}>
<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(wrapper.state().inputValue).toBe('');
});
});