@@ -9,7 +9,7 @@ import * as React from 'react';
9
9
import LegacyContext from './LegacyContext' ;
10
10
import TreeSelectContext from './TreeSelectContext' ;
11
11
import type { Key , SafeKey } from './interface' ;
12
- import { getAllKeys , isCheckDisabled , isValidCount } from './utils/valueUtil' ;
12
+ import { getAllKeys , isCheckDisabled } from './utils/valueUtil' ;
13
13
14
14
const HIDDEN_STYLE = {
15
15
width : 0 ,
@@ -46,6 +46,7 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
46
46
treeTitleRender,
47
47
onPopupScroll,
48
48
maxCount,
49
+ displayValues,
49
50
} = React . useContext ( TreeSelectContext ) ;
50
51
51
52
const {
@@ -77,24 +78,6 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
77
78
( prev , next ) => next [ 0 ] && prev [ 1 ] !== next [ 1 ] ,
78
79
) ;
79
80
80
- const isOverMaxCount = React . useMemo < boolean > (
81
- ( ) => multiple && isValidCount ( maxCount ) && checkedKeys . length >= maxCount ,
82
- [ checkedKeys , maxCount , multiple ] ,
83
- ) ;
84
-
85
- const traverse = ( nodes : EventDataNode < any > [ ] ) : EventDataNode < any > [ ] => {
86
- return nodes . map ( node => ( {
87
- ...node ,
88
- disabled : isOverMaxCount && ! checkedKeys . includes ( node . key as SafeKey ) ? true : node . disabled ,
89
- children : node . children ? traverse ( node . children ) : undefined ,
90
- } ) ) ;
91
- } ;
92
-
93
- const processedTreeData = React . useMemo (
94
- ( ) => traverse ( memoTreeData ) ,
95
- [ memoTreeData , isOverMaxCount , checkedKeys ] ,
96
- ) ;
97
-
98
81
// ========================== Values ==========================
99
82
const mergedCheckedKeys = React . useMemo ( ( ) => {
100
83
if ( ! checkable ) {
@@ -202,13 +185,6 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
202
185
const [ activeKey , setActiveKey ] = React . useState < Key > ( null ) ;
203
186
const activeEntity = keyEntities [ activeKey as SafeKey ] ;
204
187
205
- const onActiveChange = ( key : Key ) => {
206
- if ( isOverMaxCount && ! checkedKeys . includes ( key ) ) {
207
- return ;
208
- }
209
- setActiveKey ( key ) ;
210
- } ;
211
-
212
188
React . useEffect ( ( ) => {
213
189
if ( ! open ) {
214
190
return ;
@@ -274,8 +250,36 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
274
250
preSearchValue !== nextSearchValue && ! ! ( nextSearchValue || nextExcludeSearchExpandedKeys ) ,
275
251
) ;
276
252
253
+ const onActiveChange = ( key : Key ) => {
254
+ if ( isOverMaxCount && ! displayValues ?. some ( v => v . value === key ) ) {
255
+ return ;
256
+ }
257
+ setActiveKey ( key ) ;
258
+ } ;
259
+
260
+ const isOverMaxCount = React . useMemo < boolean > (
261
+ ( ) => multiple && maxCount !== undefined && displayValues ?. length >= maxCount ,
262
+ [ multiple , maxCount , displayValues ?. length ] ,
263
+ ) ;
264
+
265
+ const traverse = ( nodes : EventDataNode < any > [ ] ) : EventDataNode < any > [ ] => {
266
+ return nodes . map ( node => ( {
267
+ ...node ,
268
+ disabled :
269
+ isOverMaxCount && ! displayValues ?. some ( v => v . value === node [ fieldNames . value ] )
270
+ ? true
271
+ : node . disabled ,
272
+ children : node . children ? traverse ( node . children ) : undefined ,
273
+ } ) ) ;
274
+ } ;
275
+
276
+ const processedTreeData = React . useMemo (
277
+ ( ) => traverse ( memoTreeData ) ,
278
+ [ memoTreeData , isOverMaxCount , displayValues , fieldNames ] ,
279
+ ) ;
280
+
277
281
// ========================== Render ==========================
278
- if ( memoTreeData . length === 0 ) {
282
+ if ( processedTreeData . length === 0 ) {
279
283
return (
280
284
< div role = "listbox" className = { `${ prefixCls } -empty` } onMouseDown = { onListMouseDown } >
281
285
{ notFoundContent }
0 commit comments