From 782124dcc2ee58ffc7076f5b574c9c390d177948 Mon Sep 17 00:00:00 2001 From: zombiej Date: Mon, 13 Dec 2021 14:56:44 +0800 Subject: [PATCH] fix: disabled option should not show rm icon --- src/Select.tsx | 21 ++++++++++++--------- tests/Multiple.test.tsx | 12 ++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/Select.tsx b/src/Select.tsx index c20d830f6..a950a1e29 100644 --- a/src/Select.tsx +++ b/src/Select.tsx @@ -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)) { @@ -268,18 +269,19 @@ 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.'); + } } } @@ -287,6 +289,7 @@ const Select = React.forwardRef( label: rawLabel, value: rawValue, key: rawKey, + disabled: rawDisabled, }; }); }, diff --git a/tests/Multiple.test.tsx b/tests/Multiple.test.tsx index 855a8394d..8abb42aea 100644 --- a/tests/Multiple.test.tsx +++ b/tests/Multiple.test.tsx @@ -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( + , + ); + + expect(wrapper.exists('.rc-select-selection-item-remove')).toBeFalsy(); + }); });