From 5dd7a5773466eec8c53afd1a137543f29bb78c8b Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Sat, 12 Mar 2022 13:35:23 +0800 Subject: [PATCH] fix: tree-select not disable parent cannot checked, close #5316 --- components/vc-tree-select/OptionList.tsx | 16 ++++++++++------ components/vc-tree-select/TreeSelect.tsx | 11 ++++++++++- components/vc-tree-select/index.tsx | 2 +- components/vc-tree-select/utils/strategyUtil.ts | 1 + 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/components/vc-tree-select/OptionList.tsx b/components/vc-tree-select/OptionList.tsx index 13e937710..832d6ce90 100644 --- a/components/vc-tree-select/OptionList.tsx +++ b/components/vc-tree-select/OptionList.tsx @@ -151,13 +151,16 @@ export default defineComponent({ // >>> Select item case KeyCode.ENTER: { - const { selectable, value } = activeEntity.value?.node || {}; - if (activeEntity.value && selectable !== false) { - onInternalSelect(null, { - node: { key: activeKey.value }, - selected: !legacyContext.checkedKeys.includes(value), - }); + if (activeEntity.value) { + const { selectable, value } = activeEntity.value.node || {}; + if (selectable !== false) { + onInternalSelect(null, { + node: { key: activeKey.value }, + selected: !legacyContext.checkedKeys.includes(value), + }); + } } + break; } @@ -233,6 +236,7 @@ export default defineComponent({ showLine={treeLine} loadData={searchValue ? null : (loadData as any)} motion={treeMotion} + activeKey={activeKey.value} // We handle keys by out instead tree self checkable={checkable} checkStrictly diff --git a/components/vc-tree-select/TreeSelect.tsx b/components/vc-tree-select/TreeSelect.tsx index 0d900158f..2b3032685 100644 --- a/components/vc-tree-select/TreeSelect.tsx +++ b/components/vc-tree-select/TreeSelect.tsx @@ -387,7 +387,15 @@ export default defineComponent({ const values = displayKeys.map( key => keyEntities.value[key]?.node?.[mergedFieldNames.value.value] ?? key, ); - const rawDisplayValues = convert2LabelValues(values); + // Back fill with origin label + const labeledValues = values.map(val => { + const targetItem = rawLabeledValues.value.find(item => item.value === val); + return { + value: val, + label: targetItem?.label, + }; + }); + const rawDisplayValues = convert2LabelValues(labeledValues); const firstVal = rawDisplayValues[0]; @@ -728,6 +736,7 @@ export default defineComponent({ emptyOptions={!mergedTreeData.value.length} onDropdownVisibleChange={onInternalDropdownVisibleChange} tagRender={props.tagRender || slots.tagRender} + dropdownMatchSelectWidth={props.dropdownMatchSelectWidth ?? true} /> ); }; diff --git a/components/vc-tree-select/index.tsx b/components/vc-tree-select/index.tsx index 97d659e85..d12693095 100644 --- a/components/vc-tree-select/index.tsx +++ b/components/vc-tree-select/index.tsx @@ -1,4 +1,4 @@ -// base rc-tree-select@5.0.0-alpha.4 +// base rc-tree-select@5.1.4 import type { TreeSelectProps } from './TreeSelect'; import TreeSelect, { treeSelectProps } from './TreeSelect'; import TreeNode from './TreeNode'; diff --git a/components/vc-tree-select/utils/strategyUtil.ts b/components/vc-tree-select/utils/strategyUtil.ts index c40be6ac8..a7c28a69f 100644 --- a/components/vc-tree-select/utils/strategyUtil.ts +++ b/components/vc-tree-select/utils/strategyUtil.ts @@ -24,6 +24,7 @@ export function formatStrategyValues( if ( entity && entity.children && + entity.children.some(({ node }) => valueSet.has(node[fieldNames.value])) && entity.children.every( ({ node }) => isCheckDisabled(node) || valueSet.has(node[fieldNames.value]), )