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
21 changes: 12 additions & 9 deletions src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ const Select = React.forwardRef(
let rawValue: RawValueType;
let rawLabel: React.ReactNode;
let rawKey: React.Key;
let rawDisabled: boolean | undefined;

// Fill label & value
if (isRawValue(val)) {
Expand All @@ -268,25 +269,27 @@ const Select = React.forwardRef(
rawValue = val.value ?? rawKey;
}

// If label is not provided, fill it
if (rawLabel === undefined || rawKey === undefined) {
const option = valueOptions.get(rawValue);
const option = valueOptions.get(rawValue);
if (option) {
// Fill missing props
if (rawLabel === undefined) rawLabel = option?.[mergedFieldNames.label];
if (rawKey === undefined) rawKey = option?.key ?? rawValue;
}
rawDisabled = option?.disabled;

// Warning if label not same as provided
if (process.env.NODE_ENV !== 'production' && !isRawValue(val)) {
const optionLabel = valueOptions.get(rawValue)?.[mergedFieldNames.label];
if (optionLabel !== undefined && optionLabel !== rawLabel) {
warning(false, '`label` of `value` is not same as `label` in Select options.');
// Warning if label not same as provided
if (process.env.NODE_ENV !== 'production' && !isRawValue(val)) {
const optionLabel = option?.[mergedFieldNames.label];
if (optionLabel !== undefined && optionLabel !== rawLabel) {
warning(false, '`label` of `value` is not same as `label` in Select options.');
}
}
}

return {
label: rawLabel,
value: rawValue,
key: rawKey,
disabled: rawDisabled,
};
});
},
Expand Down
12 changes: 12 additions & 0 deletions tests/Multiple.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -462,4 +462,16 @@ describe('Select.Multiple', () => {
);
expect(wrapper.find('.rc-select-selection-item').first().prop('title')).toBe(undefined);
});

it('disabled should not show remove icon', () => {
const wrapper = mount(
<Select mode="multiple" value={[1]}>
<Option value={1} disabled>
1
</Option>
</Select>,
);

expect(wrapper.exists('.rc-select-selection-item-remove')).toBeFalsy();
});
});