Skip to content

Commit a90fceb

Browse files
icaife礼上
andauthored
feat: fix js error if value not in options (#723)
* feat: fix js error if value not in options * feat: 添加测试用例 * feat: 添加测试用例 * feat: 添加测试用例 * feat: 添加测试用例 Co-authored-by: 礼上 <[email protected]>
1 parent 4bc806f commit a90fceb

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/Select.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ const Select = React.forwardRef(
450450
? {
451451
label: option?.[mergedFieldNames.label],
452452
value: val,
453-
key: option.key ?? val,
453+
key: option?.key ?? val,
454454
}
455455
: val,
456456
injectPropsWithOption(option),

tests/Multiple.test.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,27 @@ describe('Select.Multiple', () => {
475475
expect(wrapper.exists('.rc-select-selection-item-remove')).toBeFalsy();
476476
});
477477

478+
it('do not crash if value not in options when removing option', () => {
479+
const wrapper = mount(
480+
<Select
481+
defaultValue={[
482+
{
483+
label: 'value not in options',
484+
value: 'value-not-in-options',
485+
},
486+
]}
487+
mode="multiple"
488+
labelInValue
489+
>
490+
<Option value={1}>1</Option>
491+
<Option value={2}>2</Option>
492+
</Select>,
493+
);
494+
expect(findSelection(wrapper, 0).text()).toEqual('value not in options');
495+
removeSelection(wrapper, 0);
496+
expect(wrapper.find('Selector').props().values.length).toEqual(0);
497+
});
498+
478499
describe('optionLabelProp', () => {
479500
it('basic', () => {
480501
const wrapper = mount(

0 commit comments

Comments
 (0)