Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: incorrect display when value is null in multiple mode #1009

Merged
merged 2 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,16 @@ const Select = React.forwardRef(

// Merged value with LabelValueType
const rawLabeledValues = React.useMemo(() => {
const values = convert2LabelValues(internalValue);
const newInternalValue = multiple && internalValue === null ? [] : internalValue;
const values = convert2LabelValues(newInternalValue);

// combobox no need save value when it's no value (exclude value equal 0)
if (mode === 'combobox' && isComboNoValue(values[0]?.value)) {
return [];
}

return values;
}, [internalValue, convert2LabelValues, mode]);
}, [internalValue, convert2LabelValues, mode, multiple]);

// Fill label with cache to avoid option remove
const [mergedValues, getMixedOption] = useCache(rawLabeledValues, valueOptions);
Expand Down
18 changes: 18 additions & 0 deletions tests/Multiple.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,24 @@ describe('Select.Multiple', () => {
expect(wrapper.find('Selector').props().values.length).toEqual(0);
});

it('display correctly when value is undefined or null', () => {
const wrapper1 = mount(
<Select mode="multiple" value={undefined}>
<Option value={1}>1</Option>
<Option value={2}>2</Option>
</Select>,
);
const wrapper2 = mount(
<Select mode="multiple" value={null}>
<Option value={1}>1</Option>
<Option value={2}>2</Option>
</Select>,
);

expect(wrapper1.find('.rc-select-selection-item').length).toBe(0);
expect(wrapper2.find('.rc-select-selection-item').length).toBe(0);
});

describe('optionLabelProp', () => {
it('basic', () => {
const wrapper = mount(
Expand Down
Loading