diff --git a/src/Select.tsx b/src/Select.tsx index 99e72bfe9..72c33317a 100644 --- a/src/Select.tsx +++ b/src/Select.tsx @@ -450,7 +450,7 @@ const Select = React.forwardRef( ? { label: option?.[mergedFieldNames.label], value: val, - key: option.key ?? val, + key: option?.key ?? val, } : val, injectPropsWithOption(option), diff --git a/tests/Multiple.test.tsx b/tests/Multiple.test.tsx index a5e6f6b6e..f4ccee4b0 100644 --- a/tests/Multiple.test.tsx +++ b/tests/Multiple.test.tsx @@ -475,6 +475,27 @@ describe('Select.Multiple', () => { expect(wrapper.exists('.rc-select-selection-item-remove')).toBeFalsy(); }); + it('do not crash if value not in options when removing option', () => { + const wrapper = mount( + , + ); + expect(findSelection(wrapper, 0).text()).toEqual('value not in options'); + removeSelection(wrapper, 0); + expect(wrapper.find('Selector').props().values.length).toEqual(0); + }); + describe('optionLabelProp', () => { it('basic', () => { const wrapper = mount(