Skip to content

Commit

Permalink
Merge 39ca4ad into 889122e
Browse files Browse the repository at this point in the history
  • Loading branch information
ZWkang committed Aug 2, 2023
2 parents 889122e + 39ca4ad commit daf16a4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,20 @@ const Select = React.forwardRef(
) {
return filteredOptions;
}

// ignore when search value equal select input value
if (filteredOptions.some((item) => item[mergedFieldNames.value] === mergedSearchValue)) {
return filteredOptions;
}
// Fill search value as option
return [createTagOption(mergedSearchValue), ...filteredOptions];
}, [createTagOption, optionFilterProp, mode, filteredOptions, mergedSearchValue]);
}, [
createTagOption,
optionFilterProp,
mode,
filteredOptions,
mergedSearchValue,
mergedFieldNames,
]);

const orderedFilteredOptions = React.useMemo(() => {
if (!filterSort) {
Expand Down
22 changes: 22 additions & 0 deletions tests/Tags.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -483,4 +483,26 @@ describe('Select.Tags', () => {

expect(preventDefault).toHaveBeenCalled();
});

// https://github.com/ant-design/ant-design/issues/43954
it('when insert a same input is one of options value, should not create a tag option', () => {
const errSpy = jest.spyOn(console, 'error');

const wrapper = mount(
<Select
mode="tags"
options={[
{ label: 'US-美国', value: 'US' },
{ label: 'CN-中国', value: 'CN' },
]}
optionFilterProp="label"
/>,
);
toggleOpen(wrapper);
expect(wrapper.find('.rc-select-item-option').length).toBe(2);
wrapper.find('input').simulate('change', { target: { value: 'US' } });

expect(wrapper.find('.rc-select-item-option').length).toBe(1);
expect(errSpy).not.toHaveBeenCalled();
});
});

0 comments on commit daf16a4

Please sign in to comment.