diff --git a/src/OptionList.tsx b/src/OptionList.tsx index a151c865..c2af9000 100644 --- a/src/OptionList.tsx +++ b/src/OptionList.tsx @@ -93,7 +93,7 @@ const OptionList: React.ForwardRefRenderFunction = (_, r } return rawValues.has(value); }, - [mode, [...rawValues].toString(), rawValues.size], + [mode, rawValues], ); // ========================== Active ========================== @@ -141,7 +141,7 @@ const OptionList: React.ForwardRefRenderFunction = (_, r } return rawValues.has(value); }, - [mode, searchValue, [...rawValues].toString(), rawValues.size], + [mode, searchValue, rawValues], ); // Auto scroll to item position in single mode diff --git a/tests/OptionList.test.tsx b/tests/OptionList.test.tsx index 9cbda042..2beb1250 100644 --- a/tests/OptionList.test.tsx +++ b/tests/OptionList.test.tsx @@ -582,4 +582,62 @@ describe('OptionList', () => { }); }); }); + + it('should update selected state when value changes between number and string with same string form', () => { + const options = [ + { key: 'num-1', value: 1, label: 'Number 1' }, + { key: 'str-1', value: '1', label: 'String 1' }, + ]; + + const { container, rerender } = render( + ); + + items = container.querySelectorAll('.rc-select-item-option'); + expect(items[0]).not.toHaveClass('rc-select-item-option-selected'); + expect(items[0]).toHaveAttribute('aria-selected', 'false'); + expect(items[1]).toHaveClass('rc-select-item-option-selected'); + expect(items[1]).toHaveAttribute('aria-selected', 'true'); + }); + + it('should update selected state when multiple values have the same comma-joined string', () => { + const options = [ + { value: 'a,b', label: 'a,b' }, + { value: 'c', label: 'c' }, + { value: 'a', label: 'a' }, + { value: 'b,c', label: 'b,c' }, + ]; + + const { container, rerender } = render( + , + ); + + items = container.querySelectorAll('.rc-select-item-option'); + expect(items[0]).not.toHaveClass('rc-select-item-option-selected'); + expect(items[0]).toHaveAttribute('aria-selected', 'false'); + expect(items[1]).not.toHaveClass('rc-select-item-option-selected'); + expect(items[1]).toHaveAttribute('aria-selected', 'false'); + expect(items[2]).toHaveClass('rc-select-item-option-selected'); + expect(items[2]).toHaveAttribute('aria-selected', 'true'); + expect(items[3]).toHaveClass('rc-select-item-option-selected'); + expect(items[3]).toHaveAttribute('aria-selected', 'true'); + }); });