From b541b1956edc58c8e3194341284ccd6f78c706d3 Mon Sep 17 00:00:00 2001 From: zombiej Date: Tue, 14 Sep 2021 10:57:57 +0800 Subject: [PATCH] fix: Disabled option should also show in checked --- src/OptionList.tsx | 3 ++- src/generate.tsx | 1 + tests/Select.checkable.spec.js | 28 ++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/OptionList.tsx b/src/OptionList.tsx index 1c4bef11..e793e395 100644 --- a/src/OptionList.tsx +++ b/src/OptionList.tsx @@ -106,7 +106,8 @@ const OptionList: React.RefForwardingComponent< const valueKeys = React.useMemo( () => checkedKeys.map(val => { - const entity = getEntityByValue(val); + // We should keep disabled value entity here + const entity = getEntityByValue(val, undefined, true); return entity ? entity.key : null; }), [checkedKeys, getEntityByValue], diff --git a/src/generate.tsx b/src/generate.tsx index cefd18ca..341dbfe9 100644 --- a/src/generate.tsx +++ b/src/generate.tsx @@ -326,6 +326,7 @@ export default function generate(config: { } return [newRawValues, valueHalfCheckedKeys]; }, [value, mergedMultiple, mergedLabelInValue, treeCheckable, treeCheckStrictly]); + const selectValues = useSelectValues(rawValues, { treeConduction, value, diff --git a/tests/Select.checkable.spec.js b/tests/Select.checkable.spec.js index 727e44ec..3f3a301a 100644 --- a/tests/Select.checkable.spec.js +++ b/tests/Select.checkable.spec.js @@ -684,4 +684,32 @@ describe('TreeSelect.checkable', () => { wrapper.selectNode(1); expect(onChange).toHaveBeenCalledWith([], expect.anything(), expect.anything()); }); + + it('disabled option should keep check', () => { + const wrapper = mount( + , + ); + + expect(wrapper.exists('.rc-tree-select-tree-treenode-checkbox-checked')).toBeTruthy(); + }); });