@@ -12,6 +12,8 @@ import TreeSelectContext from './TreeSelectContext';
12
12
import type { DataNode , Key , SafeKey } from './interface' ;
13
13
import { getAllKeys , isCheckDisabled } from './utils/valueUtil' ;
14
14
import { useEvent } from 'rc-util' ;
15
+ import { formatStrategyValues } from './utils/strategyUtil' ;
16
+ import { conductCheck } from 'rc-tree/lib/utils/conductUtil' ;
15
17
16
18
const HIDDEN_STYLE = {
17
19
width : 0 ,
@@ -49,6 +51,8 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
49
51
onPopupScroll,
50
52
displayValues,
51
53
isOverMaxCount,
54
+ maxCount,
55
+ showCheckedStrategy,
52
56
} = React . useContext ( TreeSelectContext ) ;
53
57
54
58
const {
@@ -164,7 +168,57 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
164
168
} , [ searchValue ] ) ;
165
169
166
170
const nodeDisabled = useEvent ( ( node : DataNode ) => {
167
- return isOverMaxCount && ! memoRawValues . includes ( node [ fieldNames . value ] ) ;
171
+ // Always enable selected nodes
172
+ if ( checkedKeys . includes ( node [ fieldNames . value ] ) ) {
173
+ return false ;
174
+ }
175
+
176
+ // Get all selectable keys under current node considering conduction rules
177
+ const getSelectableKeys = ( nodes : DataNode [ ] ) => {
178
+ const keys : Key [ ] = [ ] ;
179
+ const traverse = ( n : DataNode ) => {
180
+ if ( ! n . disabled ) {
181
+ keys . push ( n [ fieldNames . value ] ) ;
182
+ // Only traverse children if node is not disabled
183
+ if ( Array . isArray ( n . children ) ) {
184
+ n . children . forEach ( traverse ) ;
185
+ }
186
+ }
187
+ } ;
188
+ nodes . forEach ( traverse ) ;
189
+ return keys ;
190
+ } ;
191
+
192
+ const selectableNodeValues = getSelectableKeys ( [ node ] ) ;
193
+
194
+ // Simulate checked state after selecting current node
195
+ const simulatedCheckedKeys = [ ...checkedKeys , ...selectableNodeValues ] ;
196
+
197
+ const { checkedKeys : conductedKeys } = conductCheck ( simulatedCheckedKeys , true , keyEntities ) ;
198
+
199
+ // Calculate display keys based on strategy
200
+ const simulatedDisplayKeys = formatStrategyValues (
201
+ conductedKeys as SafeKey [ ] ,
202
+ showCheckedStrategy ,
203
+ keyEntities ,
204
+ fieldNames ,
205
+ ) ;
206
+
207
+ const currentDisplayKeys = formatStrategyValues (
208
+ checkedKeys as SafeKey [ ] ,
209
+ showCheckedStrategy ,
210
+ keyEntities ,
211
+ fieldNames ,
212
+ ) ;
213
+
214
+ const newDisplayValuesCount = simulatedDisplayKeys . length - currentDisplayKeys . length ;
215
+
216
+ // Check if selecting this node would exceed maxCount
217
+ if ( isOverMaxCount || memoRawValues . length + newDisplayValuesCount > maxCount ) {
218
+ return true ;
219
+ }
220
+
221
+ return false ;
168
222
} ) ;
169
223
170
224
// ========================== Get First Selectable Node ==========================
0 commit comments