@@ -45,6 +45,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
45
45
onPopupScroll,
46
46
} = useBaseProps ( ) ;
47
47
const {
48
+ maxCount,
48
49
flattenOptions,
49
50
onActiveValue,
50
51
defaultActiveFirstOption,
@@ -70,6 +71,11 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
70
71
// =========================== List ===========================
71
72
const listRef = React . useRef < ListRef > ( null ) ;
72
73
74
+ const overMaxCount = React . useMemo < boolean > (
75
+ ( ) => multiple && typeof maxCount !== 'undefined' && rawValues . size >= maxCount ,
76
+ [ multiple , maxCount , rawValues . size ] ,
77
+ ) ;
78
+
73
79
const onListMouseDown : React . MouseEventHandler < HTMLDivElement > = ( event ) => {
74
80
event . preventDefault ( ) ;
75
81
} ;
@@ -87,9 +93,9 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
87
93
for ( let i = 0 ; i < len ; i += 1 ) {
88
94
const current = ( index + i * offset + len ) % len ;
89
95
90
- const { group, data } = memoFlattenOptions [ current ] ;
96
+ const { group, data } = memoFlattenOptions [ current ] || { } ;
91
97
92
- if ( ! group && ! data . disabled ) {
98
+ if ( ! group && ! data ? .disabled && ! overMaxCount ) {
93
99
return current ;
94
100
}
95
101
}
@@ -198,7 +204,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
198
204
case KeyCode . ENTER : {
199
205
// value
200
206
const item = memoFlattenOptions [ activeIndex ] ;
201
- if ( item && ! item . data . disabled ) {
207
+ if ( item && ! item ? .data ? .disabled && ! overMaxCount ) {
202
208
onSelectValue ( item . value ) ;
203
209
} else {
204
210
onSelectValue ( undefined ) ;
@@ -256,8 +262,9 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
256
262
257
263
const renderItem = ( index : number ) => {
258
264
const item = memoFlattenOptions [ index ] ;
259
- if ( ! item ) return null ;
260
-
265
+ if ( ! item ) {
266
+ return null ;
267
+ }
261
268
const itemData = item . data || { } ;
262
269
const { value } = itemData ;
263
270
const { group } = item ;
@@ -327,11 +334,13 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
327
334
// Option
328
335
const selected = isSelected ( value ) ;
329
336
337
+ const mergedDisabled = disabled || ( ! selected && overMaxCount ) ;
338
+
330
339
const optionPrefixCls = `${ itemPrefixCls } -option` ;
331
340
const optionClassName = classNames ( itemPrefixCls , optionPrefixCls , className , {
332
341
[ `${ optionPrefixCls } -grouped` ] : groupOption ,
333
- [ `${ optionPrefixCls } -active` ] : activeIndex === itemIndex && ! disabled ,
334
- [ `${ optionPrefixCls } -disabled` ] : disabled ,
342
+ [ `${ optionPrefixCls } -active` ] : activeIndex === itemIndex && ! mergedDisabled ,
343
+ [ `${ optionPrefixCls } -disabled` ] : mergedDisabled ,
335
344
[ `${ optionPrefixCls } -selected` ] : selected ,
336
345
} ) ;
337
346
@@ -356,13 +365,13 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
356
365
className = { optionClassName }
357
366
title = { optionTitle }
358
367
onMouseMove = { ( ) => {
359
- if ( activeIndex === itemIndex || disabled ) {
368
+ if ( activeIndex === itemIndex || mergedDisabled ) {
360
369
return ;
361
370
}
362
371
setActive ( itemIndex ) ;
363
372
} }
364
373
onClick = { ( ) => {
365
- if ( ! disabled ) {
374
+ if ( ! mergedDisabled ) {
366
375
onSelectValue ( value ) ;
367
376
}
368
377
} }
@@ -380,7 +389,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
380
389
customizeIcon = { menuItemSelectedIcon }
381
390
customizeIconProps = { {
382
391
value,
383
- disabled,
392
+ disabled : mergedDisabled ,
384
393
isSelected : selected ,
385
394
} }
386
395
>
0 commit comments