Skip to content
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
45 changes: 27 additions & 18 deletions src/generate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -454,24 +454,33 @@ export default function generateSelector<
}, [mergedSearchValue]);

// ============================ Selector ============================
let displayValues = React.useMemo<DisplayLabelValueType[]>(
() =>
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<DisplayLabelValueType[]>(() => {
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);
Expand Down
24 changes: 19 additions & 5 deletions tests/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1593,11 +1593,25 @@ describe('Select.Basic', () => {
});
});

it('show placeholder when searchValue is controlled', () => {
const wrapper = mount(<Select searchValue="light" placeholder="bamboo" />);
expect(wrapper.find('.rc-select-selection-placeholder').length).toBeTruthy();
toggleOpen(wrapper);
expect(wrapper.find('.rc-select-selection-placeholder').length).toBeFalsy();
describe('show placeholder', () => {
it('when searchValue is controlled', () => {
const wrapper = mount(<Select searchValue="light" placeholder="bamboo" />);
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(<Select value={null} placeholder="bamboo" />);
expect(wrapper.find('.rc-select-selection-placeholder').length).toBeTruthy();
});

it('not when value is null but it is an Option', () => {
const wrapper = mount(
<Select value={null} placeholder="bamboo" options={[{ value: null, label: 'light' }]} />,
);
expect(wrapper.find('.rc-select-selection-placeholder').length).toBeFalsy();
});
});

it('Remove options can keep the cache', () => {
Expand Down