@@ -3,7 +3,7 @@ import type { RefOptionListProps } from '@rc-component/select/lib/OptionList';
3
3
import type { TreeProps } from '@rc-component/tree' ;
4
4
import Tree from '@rc-component/tree' ;
5
5
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' ;
7
7
import KeyCode from '@rc-component/util/lib/KeyCode' ;
8
8
import useMemo from '@rc-component/util/lib/hooks/useMemo' ;
9
9
import * as React from 'react' ;
@@ -178,14 +178,31 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
178
178
const isLeaf = ( entity . children || [ ] ) . length === 0 ;
179
179
180
180
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 ) ;
189
206
disabledCache . set ( value , checkableChildrenCount > leftMaxCount ) ;
190
207
} else {
191
208
disabledCache . set ( value , false ) ;
0 commit comments