From 7166145e41e7a5283270475fbb732c1c64b2d9d5 Mon Sep 17 00:00:00 2001 From: zombiej Date: Thu, 6 Aug 2020 16:26:21 +0800 Subject: [PATCH 1/3] test: Add missing test --- tests/Multiple.test.tsx | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/tests/Multiple.test.tsx b/tests/Multiple.test.tsx index bcb014495..d9e30ddef 100644 --- a/tests/Multiple.test.tsx +++ b/tests/Multiple.test.tsx @@ -121,7 +121,7 @@ describe('Select.Multiple', () => { expect(wrapper.find('input').props().value).toBe(''); }); - it('shouldn\'t separate words when compositing', () => { + it("shouldn't separate words when compositing", () => { const handleChange = jest.fn(); const handleSelect = jest.fn(); const wrapper = mount( @@ -391,4 +391,38 @@ describe('Select.Multiple', () => { toggleOpen(wrapper); expect(wrapper.find('input').props().value).toEqual(''); }); + + it('ajax update should keep options', () => { + const onChange = jest.fn(); + + const wrapper = mount( + { toggleOpen(wrapper); selectItem(wrapper, 0); expect(onChange).toHaveBeenCalledWith( - ['light'], + [{ label: 'Light', value: 'light', key: 'light' }], [{ label: 'Light', value: 'light', option: 2333 }], ); onChange.mockReset(); @@ -418,7 +419,10 @@ describe('Select.Multiple', () => { toggleOpen(wrapper); selectItem(wrapper, 0); expect(onChange).toHaveBeenCalledWith( - ['light', 'bamboo'], + [ + { label: 'Light', value: 'light', key: 'light' }, + { label: 'Bamboo', value: 'bamboo', key: 'bamboo' }, + ], [ { label: 'Light', value: 'light', option: 2333 }, { value: 'bamboo', label: 'Bamboo', option: 444 }, From 57d1edd5a29f3fafde1092823f251f8dd86f0e24 Mon Sep 17 00:00:00 2001 From: zombiej Date: Thu, 6 Aug 2020 16:59:10 +0800 Subject: [PATCH 3/3] fix ts --- src/generate.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/generate.tsx b/src/generate.tsx index 4062f114b..e4c172409 100644 --- a/src/generate.tsx +++ b/src/generate.tsx @@ -187,11 +187,15 @@ export interface GenerateConfig { /** Convert single raw value into { label, value } format. Will be called by each value */ getLabeledValue: GetLabeledValue>; filterOptions: FilterOptions; - findValueOption: ( - values: RawValueType[], - options: FlattenOptionsType, - info?: { prevValueOptions?: OptionsType[] }, - ) => OptionsType; + findValueOption: + | (// Need still support legacy ts api + (values: RawValueType[], options: FlattenOptionsType) => OptionsType) + | (// New API add prevValueOptions support + ( + values: RawValueType[], + options: FlattenOptionsType, + info?: { prevValueOptions?: OptionsType[] }, + ) => OptionsType); /** Check if a value is disabled */ isValueDisabled: (value: RawValueType, options: FlattenOptionsType) => boolean; warningProps?: (props: any) => void;