diff --git a/src/generate.tsx b/src/generate.tsx index 7c989a353..1f39ee25d 100644 --- a/src/generate.tsx +++ b/src/generate.tsx @@ -454,24 +454,33 @@ export default function generateSelector< }, [mergedSearchValue]); // ============================ Selector ============================ - let displayValues = React.useMemo( - () => - mergedRawValue.map((val: RawValueType) => { - const valueOptions = getValueOption([val]); - const displayValue = getLabeledValue(val, { - options: valueOptions, - prevValue: baseValue, - labelInValue: mergedLabelInValue, - optionLabelProp: mergedOptionLabelProp, - }); - - return { - ...displayValue, - disabled: isValueDisabled(val, valueOptions), - }; - }), - [baseValue, mergedOptions], - ); + let displayValues = React.useMemo(() => { + const tmpValues = mergedRawValue.map((val: RawValueType) => { + const valueOptions = getValueOption([val]); + const displayValue = getLabeledValue(val, { + options: valueOptions, + prevValue: baseValue, + labelInValue: mergedLabelInValue, + optionLabelProp: mergedOptionLabelProp, + }); + + return { + ...displayValue, + disabled: isValueDisabled(val, valueOptions), + }; + }); + + if ( + !mode && + tmpValues.length === 1 && + tmpValues[0].value === null && + tmpValues[0].label === null + ) { + return []; + } + + return tmpValues; + }, [baseValue, mergedOptions, mode]); // Polyfill with cache label displayValues = useCacheDisplayValue(displayValues); diff --git a/tests/Select.test.tsx b/tests/Select.test.tsx index 5a0970472..fed60225f 100644 --- a/tests/Select.test.tsx +++ b/tests/Select.test.tsx @@ -1593,11 +1593,25 @@ describe('Select.Basic', () => { }); }); - it('show placeholder when searchValue is controlled', () => { - const wrapper = mount(); + expect(wrapper.find('.rc-select-selection-placeholder').length).toBeTruthy(); + toggleOpen(wrapper); + expect(wrapper.find('.rc-select-selection-placeholder').length).toBeFalsy(); + }); + + it('when value is null', () => { + const wrapper = mount(, + ); + expect(wrapper.find('.rc-select-selection-placeholder').length).toBeFalsy(); + }); }); it('Remove options can keep the cache', () => {