Skip to content

Commit cdff8c1

Browse files
committed
fix:parent node not disabled when child nodes count greater than maxCount
1 parent 6fa2d68 commit cdff8c1

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

src/OptionList.tsx

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { RefOptionListProps } from '@rc-component/select/lib/OptionList';
33
import type { TreeProps } from '@rc-component/tree';
44
import Tree from '@rc-component/tree';
55
import { UnstableContext } from '@rc-component/tree';
6-
import type { EventDataNode, ScrollTo } from '@rc-component/tree/lib/interface';
6+
import type { DataEntity, EventDataNode, ScrollTo } from '@rc-component/tree/lib/interface';
77
import KeyCode from '@rc-component/util/lib/KeyCode';
88
import useMemo from '@rc-component/util/lib/hooks/useMemo';
99
import * as React from 'react';
@@ -178,14 +178,31 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
178178
const isLeaf = (entity.children || []).length === 0;
179179

180180
if (!isLeaf) {
181-
const checkableChildren = entity.children.filter(
182-
childTreeNode =>
183-
!childTreeNode.node.disabled &&
184-
!childTreeNode.node.disableCheckbox &&
185-
!checkedKeys.includes(childTreeNode.node[fieldNames.value]),
186-
);
187-
188-
const checkableChildrenCount = checkableChildren.length;
181+
const getLeafCheckableCount = (children: DataEntity<DataNode>[]): number => {
182+
return children.reduce((count, current) => {
183+
const currentValue = current.node[fieldNames.value];
184+
const currentEntity = valueEntities.get(currentValue);
185+
const isCurrentLeaf = (currentEntity.children || []).length === 0;
186+
187+
if (isCurrentLeaf) {
188+
if (
189+
!current.node.disabled &&
190+
!current.node.disableCheckbox &&
191+
!checkedKeys.includes(currentValue)
192+
) {
193+
return count + 1;
194+
}
195+
} else if (
196+
!current.node.disabled &&
197+
!current.node.disableCheckbox &&
198+
!checkedKeys.includes(currentValue)
199+
) {
200+
return count + getLeafCheckableCount(currentEntity.children);
201+
}
202+
return count;
203+
}, 0);
204+
};
205+
const checkableChildrenCount = getLeafCheckableCount(entity.children);
189206
disabledCache.set(value, checkableChildrenCount > leftMaxCount);
190207
} else {
191208
disabledCache.set(value, false);

0 commit comments

Comments
 (0)