Skip to content

Commit

Permalink
fix(Tree): 勾选父节点时,不再返回被隐藏(hideNode)的子节点key (#685)
Browse files Browse the repository at this point in the history
  • Loading branch information
nullptr-z committed Mar 17, 2022
1 parent fe034f5 commit dacf2a8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/react-transfer/README.md
Expand Up @@ -57,7 +57,7 @@ function Demo() {
label: '武汉市',
key: 1,
children: [
{ label: '新洲区', key: 2, disabled: true },
{ label: '新洲区', key: 2 },
{ label: '武昌区', key: 3 },
{
label: '汉南区',
Expand All @@ -72,7 +72,7 @@ function Demo() {
}
];

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

return (
<Row style={{ flexDirection:'column' }} >
Expand Down
13 changes: 7 additions & 6 deletions packages/react-transfer/src/index.tsx
Expand Up @@ -102,7 +102,9 @@ function Transfer(props: TransferProps) {
};
const iteratorParent = (child: TreeData) => {
if (child.parent) {
const selectCount = child.parent.children.filter((child: TreeData) => !selectOption.get(child.key!)).length;
const selectCount = child.parent.children.filter(
(child: TreeData) => !selectOption.get(child.key!) && !child.hideNode,
).length;
addOrDel(child.parent.key, child.parent.label, selectCount === 0);
iteratorParent(child.parent);
}
Expand Down Expand Up @@ -188,11 +190,10 @@ function Transfer(props: TransferProps) {
selectedOptions.forEach((child) => {
if (child.children?.length) {
selectedOptionsRecursion(child.children);
} else {
if (!child.hideNode) {
selectOption.set(child.key!, child.label as string);
keys.push(child.key!);
}
}
if (!child.hideNode) {
selectOption.set(child.key!, child.label as string);
keys.push(child.key!);
}
});
};
Expand Down
4 changes: 3 additions & 1 deletion packages/react-tree/src/index.tsx
Expand Up @@ -78,7 +78,9 @@ export const getChildKeys = (
depth?: number,
): TreeData['key'][] => {
childs.forEach((item) => {
result.push(item.key as string | number);
if (!item.hideNode) {
result.push(item.key as string | number);
}
if (typeof depth === 'number' && !(depth - 1)) return;

if (item.children && item.children.length > 0) {
Expand Down

0 comments on commit dacf2a8

Please sign in to comment.