@@ -45,6 +45,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
4545 onPopupScroll,
4646 } = useBaseProps ( ) ;
4747 const {
48+ maxCount,
4849 flattenOptions,
4950 onActiveValue,
5051 defaultActiveFirstOption,
@@ -70,6 +71,11 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
7071 // =========================== List ===========================
7172 const listRef = React . useRef < ListRef > ( null ) ;
7273
74+ const overMaxCount = React . useMemo < boolean > (
75+ ( ) => multiple && typeof maxCount !== 'undefined' && rawValues . size >= maxCount ,
76+ [ multiple , maxCount , rawValues . size ] ,
77+ ) ;
78+
7379 const onListMouseDown : React . MouseEventHandler < HTMLDivElement > = ( event ) => {
7480 event . preventDefault ( ) ;
7581 } ;
@@ -87,9 +93,9 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
8793 for ( let i = 0 ; i < len ; i += 1 ) {
8894 const current = ( index + i * offset + len ) % len ;
8995
90- const { group, data } = memoFlattenOptions [ current ] ;
96+ const { group, data } = memoFlattenOptions [ current ] || { } ;
9197
92- if ( ! group && ! data . disabled ) {
98+ if ( ! group && ! data ? .disabled && ! overMaxCount ) {
9399 return current ;
94100 }
95101 }
@@ -198,7 +204,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
198204 case KeyCode . ENTER : {
199205 // value
200206 const item = memoFlattenOptions [ activeIndex ] ;
201- if ( item && ! item . data . disabled ) {
207+ if ( item && ! item ? .data ? .disabled && ! overMaxCount ) {
202208 onSelectValue ( item . value ) ;
203209 } else {
204210 onSelectValue ( undefined ) ;
@@ -256,8 +262,9 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
256262
257263 const renderItem = ( index : number ) => {
258264 const item = memoFlattenOptions [ index ] ;
259- if ( ! item ) return null ;
260-
265+ if ( ! item ) {
266+ return null ;
267+ }
261268 const itemData = item . data || { } ;
262269 const { value } = itemData ;
263270 const { group } = item ;
@@ -327,11 +334,13 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
327334 // Option
328335 const selected = isSelected ( value ) ;
329336
337+ const mergedDisabled = disabled || ( ! selected && overMaxCount ) ;
338+
330339 const optionPrefixCls = `${ itemPrefixCls } -option` ;
331340 const optionClassName = classNames ( itemPrefixCls , optionPrefixCls , className , {
332341 [ `${ optionPrefixCls } -grouped` ] : groupOption ,
333- [ `${ optionPrefixCls } -active` ] : activeIndex === itemIndex && ! disabled ,
334- [ `${ optionPrefixCls } -disabled` ] : disabled ,
342+ [ `${ optionPrefixCls } -active` ] : activeIndex === itemIndex && ! mergedDisabled ,
343+ [ `${ optionPrefixCls } -disabled` ] : mergedDisabled ,
335344 [ `${ optionPrefixCls } -selected` ] : selected ,
336345 } ) ;
337346
@@ -356,13 +365,13 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
356365 className = { optionClassName }
357366 title = { optionTitle }
358367 onMouseMove = { ( ) => {
359- if ( activeIndex === itemIndex || disabled ) {
368+ if ( activeIndex === itemIndex || mergedDisabled ) {
360369 return ;
361370 }
362371 setActive ( itemIndex ) ;
363372 } }
364373 onClick = { ( ) => {
365- if ( ! disabled ) {
374+ if ( ! mergedDisabled ) {
366375 onSelectValue ( value ) ;
367376 }
368377 } }
@@ -380,7 +389,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
380389 customizeIcon = { menuItemSelectedIcon }
381390 customizeIconProps = { {
382391 value,
383- disabled,
392+ disabled : mergedDisabled ,
384393 isSelected : selected ,
385394 } }
386395 >
0 commit comments