Skip to content

Commit

Permalink
fix: tree-select not disable parent cannot checked, close #5316
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou committed Mar 12, 2022
1 parent f7e8999 commit 5dd7a57
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
16 changes: 10 additions & 6 deletions components/vc-tree-select/OptionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion components/vc-tree-select/TreeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -728,6 +736,7 @@ export default defineComponent({
emptyOptions={!mergedTreeData.value.length}
onDropdownVisibleChange={onInternalDropdownVisibleChange}
tagRender={props.tagRender || slots.tagRender}
dropdownMatchSelectWidth={props.dropdownMatchSelectWidth ?? true}
/>
);
};
Expand Down
2 changes: 1 addition & 1 deletion components/vc-tree-select/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
1 change: 1 addition & 0 deletions components/vc-tree-select/utils/strategyUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
)
Expand Down

0 comments on commit 5dd7a57

Please sign in to comment.