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
27 changes: 18 additions & 9 deletions src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,14 @@ class Select extends React.Component<Partial<ISelectProps>, ISelectState> {
const selectedValue = getValuePropValue(item);
const lastValue = value[value.length - 1];

let skipTrigger = false;

if (isMultipleOrTags(props)) {
if (findIndexInValueBySingleValue(value, selectedValue) !== -1) {
return;
skipTrigger = true;
} else {
value = value.concat([selectedValue]);
}
value = value.concat([selectedValue]);
} else {
if (
!isCombobox(props) &&
Expand All @@ -456,18 +459,24 @@ class Select extends React.Component<Partial<ISelectProps>, ISelectState> {
selectedValue !== this.state.backfillValue
) {
this.setOpenState(false, { needFocus: true, fireSearch: false });
return;
skipTrigger = true;
} else {
value = [selectedValue];
this.setOpenState(false, { needFocus: true, fireSearch: false });
}
value = [selectedValue];
this.setOpenState(false, { needFocus: true, fireSearch: false });
}

this.fireChange(value);
if (!skipTrigger) {
this.fireChange(value);
}
this.fireSelect(selectedValue);
const inputValue = isCombobox(props) ? getPropValue(item, props.optionLabelProp) : '';

if (props.autoClearSearchValue) {
this.setInputValue(inputValue, false);
if (!skipTrigger) {
const inputValue = isCombobox(props) ? getPropValue(item, props.optionLabelProp) : '';

if (props.autoClearSearchValue) {
this.setInputValue(inputValue, false);
}
}
};

Expand Down
18 changes: 18 additions & 0 deletions tests/Select.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1176,4 +1176,22 @@ describe('Select', () => {
});
expect(wrapper.find('.rc-select-arrow-loading').length).toBe(1);
});

it('should keep trigger onSelect by select', () => {
const onSelect = jest.fn();

const wrapper = mount<Select>(
<Select backfill={true} open={true} onSelect={onSelect} optionLabelProp="children">
<Option value="1">One</Option>
</Select>,
);

const input = wrapper.find('input');

for (let i = 0; i < 10; i += 1) {
onSelect.mockReset();
input.simulate('keyDown', { keyCode: KeyCode.ENTER });
expect(onSelect).toBeCalledWith('1', expect.anything());
}
});
});