@@ -2,14 +2,16 @@ import { useBaseProps } from 'rc-select';
2
2
import type { RefOptionListProps } from 'rc-select/lib/OptionList' ;
3
3
import type { TreeProps } from 'rc-tree' ;
4
4
import Tree from 'rc-tree' ;
5
+ import { UnstableContext } from 'rc-tree' ;
5
6
import type { EventDataNode , ScrollTo } from 'rc-tree/lib/interface' ;
6
7
import KeyCode from 'rc-util/lib/KeyCode' ;
7
8
import useMemo from 'rc-util/lib/hooks/useMemo' ;
8
9
import * as React from 'react' ;
9
10
import LegacyContext from './LegacyContext' ;
10
11
import TreeSelectContext from './TreeSelectContext' ;
11
- import type { Key , SafeKey } from './interface' ;
12
+ import type { DataNode , Key , SafeKey } from './interface' ;
12
13
import { getAllKeys , isCheckDisabled } from './utils/valueUtil' ;
14
+ import { useEvent } from 'rc-util' ;
13
15
14
16
const HIDDEN_STYLE = {
15
17
width : 0 ,
@@ -45,6 +47,8 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
45
47
treeExpandAction,
46
48
treeTitleRender,
47
49
onPopupScroll,
50
+ displayValues,
51
+ isOverMaxCount,
48
52
} = React . useContext ( TreeSelectContext ) ;
49
53
50
54
const {
@@ -76,6 +80,11 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
76
80
( prev , next ) => next [ 0 ] && prev [ 1 ] !== next [ 1 ] ,
77
81
) ;
78
82
83
+ const memoRawValues = React . useMemo (
84
+ ( ) => ( displayValues || [ ] ) . map ( v => v . value ) ,
85
+ [ displayValues ] ,
86
+ ) ;
87
+
79
88
// ========================== Values ==========================
80
89
const mergedCheckedKeys = React . useMemo ( ( ) => {
81
90
if ( ! checkable ) {
@@ -154,6 +163,10 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
154
163
// eslint-disable-next-line react-hooks/exhaustive-deps
155
164
} , [ searchValue ] ) ;
156
165
166
+ const nodeDisabled = useEvent ( ( node : DataNode ) => {
167
+ return isOverMaxCount && ! memoRawValues . includes ( node [ fieldNames . value ] ) ;
168
+ } ) ;
169
+
157
170
// ========================== Get First Selectable Node ==========================
158
171
const getFirstMatchingNode = ( nodes : EventDataNode < any > [ ] ) : EventDataNode < any > | null => {
159
172
for ( const node of nodes ) {
@@ -221,8 +234,9 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
221
234
// >>> Select item
222
235
case KeyCode . ENTER : {
223
236
if ( activeEntity ) {
237
+ const isNodeDisabled = nodeDisabled ( activeEntity . node ) ;
224
238
const { selectable, value, disabled } = activeEntity ?. node || { } ;
225
- if ( selectable !== false && ! disabled ) {
239
+ if ( selectable !== false && ! disabled && ! isNodeDisabled ) {
226
240
onInternalSelect ( null , {
227
241
node : { key : activeKey } ,
228
242
selected : ! checkedKeys . includes ( value ) ,
@@ -276,42 +290,43 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
276
290
{ activeEntity . node . value }
277
291
</ span >
278
292
) }
279
-
280
- < Tree
281
- ref = { treeRef }
282
- focusable = { false }
283
- prefixCls = { `${ prefixCls } -tree` }
284
- treeData = { memoTreeData }
285
- height = { listHeight }
286
- itemHeight = { listItemHeight }
287
- itemScrollOffset = { listItemScrollOffset }
288
- virtual = { virtual !== false && dropdownMatchSelectWidth !== false }
289
- multiple = { multiple }
290
- icon = { treeIcon }
291
- showIcon = { showTreeIcon }
292
- switcherIcon = { switcherIcon }
293
- showLine = { treeLine }
294
- loadData = { syncLoadData }
295
- motion = { treeMotion }
296
- activeKey = { activeKey }
297
- // We handle keys by out instead tree self
298
- checkable = { checkable }
299
- checkStrictly
300
- checkedKeys = { mergedCheckedKeys }
301
- selectedKeys = { ! checkable ? checkedKeys : [ ] }
302
- defaultExpandAll = { treeDefaultExpandAll }
303
- titleRender = { treeTitleRender }
304
- { ...treeProps }
305
- // Proxy event out
306
- onActiveChange = { setActiveKey }
307
- onSelect = { onInternalSelect }
308
- onCheck = { onInternalSelect }
309
- onExpand = { onInternalExpand }
310
- onLoad = { onTreeLoad }
311
- filterTreeNode = { filterTreeNode }
312
- expandAction = { treeExpandAction }
313
- onScroll = { onPopupScroll }
314
- />
293
+ < UnstableContext . Provider value = { { nodeDisabled } } >
294
+ < Tree
295
+ ref = { treeRef }
296
+ focusable = { false }
297
+ prefixCls = { `${ prefixCls } -tree` }
298
+ treeData = { memoTreeData }
299
+ height = { listHeight }
300
+ itemHeight = { listItemHeight }
301
+ itemScrollOffset = { listItemScrollOffset }
302
+ virtual = { virtual !== false && dropdownMatchSelectWidth !== false }
303
+ multiple = { multiple }
304
+ icon = { treeIcon }
305
+ showIcon = { showTreeIcon }
306
+ switcherIcon = { switcherIcon }
307
+ showLine = { treeLine }
308
+ loadData = { syncLoadData }
309
+ motion = { treeMotion }
310
+ activeKey = { activeKey }
311
+ // We handle keys by out instead tree self
312
+ checkable = { checkable }
313
+ checkStrictly
314
+ checkedKeys = { mergedCheckedKeys }
315
+ selectedKeys = { ! checkable ? checkedKeys : [ ] }
316
+ defaultExpandAll = { treeDefaultExpandAll }
317
+ titleRender = { treeTitleRender }
318
+ { ...treeProps }
319
+ // Proxy event out
320
+ onActiveChange = { setActiveKey }
321
+ onSelect = { onInternalSelect }
322
+ onCheck = { onInternalSelect }
323
+ onExpand = { onInternalExpand }
324
+ onLoad = { onTreeLoad }
325
+ filterTreeNode = { filterTreeNode }
326
+ expandAction = { treeExpandAction }
327
+ onScroll = { onPopupScroll }
328
+ />
329
+ </ UnstableContext . Provider >
315
330
</ div >
316
331
) ;
317
332
} ;
0 commit comments