Skip to content

Commit dacf2a8

Browse files
authoredMar 17, 2022
fix(Tree): 勾选父节点时,不再返回被隐藏(hideNode)的子节点key (#685)
1 parent fe034f5 commit dacf2a8

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed
 

‎packages/react-transfer/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function Demo() {
5757
label: '武汉市',
5858
key: 1,
5959
children: [
60-
{ label: '新洲区', key: 2, disabled: true },
60+
{ label: '新洲区', key: 2 },
6161
{ label: '武昌区', key: 3 },
6262
{
6363
label: '汉南区',
@@ -72,7 +72,7 @@ function Demo() {
7272
}
7373
];
7474

75-
const [value,valueSet] = React.useState([{ label: '武汉市', key: 1 }, { label: '汉南区1', key: 5 }])
75+
const [value,valueSet] = React.useState([{ label: '武昌区', key: 3 }, { label: '汉南区1', key: 5 }])
7676

7777
return (
7878
<Row style={{ flexDirection:'column' }} >

‎packages/react-transfer/src/index.tsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ function Transfer(props: TransferProps) {
102102
};
103103
const iteratorParent = (child: TreeData) => {
104104
if (child.parent) {
105-
const selectCount = child.parent.children.filter((child: TreeData) => !selectOption.get(child.key!)).length;
105+
const selectCount = child.parent.children.filter(
106+
(child: TreeData) => !selectOption.get(child.key!) && !child.hideNode,
107+
).length;
106108
addOrDel(child.parent.key, child.parent.label, selectCount === 0);
107109
iteratorParent(child.parent);
108110
}
@@ -188,11 +190,10 @@ function Transfer(props: TransferProps) {
188190
selectedOptions.forEach((child) => {
189191
if (child.children?.length) {
190192
selectedOptionsRecursion(child.children);
191-
} else {
192-
if (!child.hideNode) {
193-
selectOption.set(child.key!, child.label as string);
194-
keys.push(child.key!);
195-
}
193+
}
194+
if (!child.hideNode) {
195+
selectOption.set(child.key!, child.label as string);
196+
keys.push(child.key!);
196197
}
197198
});
198199
};

‎packages/react-tree/src/index.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ export const getChildKeys = (
7878
depth?: number,
7979
): TreeData['key'][] => {
8080
childs.forEach((item) => {
81-
result.push(item.key as string | number);
81+
if (!item.hideNode) {
82+
result.push(item.key as string | number);
83+
}
8284
if (typeof depth === 'number' && !(depth - 1)) return;
8385

8486
if (item.children && item.children.length > 0) {

0 commit comments

Comments
 (0)
Please sign in to comment.