@@ -2,14 +2,16 @@ import { useBaseProps } from 'rc-select';
22import type { RefOptionListProps } from 'rc-select/lib/OptionList' ;
33import type { TreeProps } from 'rc-tree' ;
44import Tree from 'rc-tree' ;
5+ import { UnstableContext } from 'rc-tree' ;
56import type { EventDataNode , ScrollTo } from 'rc-tree/lib/interface' ;
67import KeyCode from 'rc-util/lib/KeyCode' ;
78import useMemo from 'rc-util/lib/hooks/useMemo' ;
89import * as React from 'react' ;
910import LegacyContext from './LegacyContext' ;
1011import TreeSelectContext from './TreeSelectContext' ;
11- import type { Key , SafeKey } from './interface' ;
12+ import type { DataNode , Key , SafeKey } from './interface' ;
1213import { getAllKeys , isCheckDisabled } from './utils/valueUtil' ;
14+ import { useEvent } from 'rc-util' ;
1315
1416const HIDDEN_STYLE = {
1517 width : 0 ,
@@ -45,6 +47,8 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
4547 treeExpandAction,
4648 treeTitleRender,
4749 onPopupScroll,
50+ displayValues,
51+ isOverMaxCount,
4852 } = React . useContext ( TreeSelectContext ) ;
4953
5054 const {
@@ -76,6 +80,11 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
7680 ( prev , next ) => next [ 0 ] && prev [ 1 ] !== next [ 1 ] ,
7781 ) ;
7882
83+ const memoRawValues = React . useMemo (
84+ ( ) => ( displayValues || [ ] ) . map ( v => v . value ) ,
85+ [ displayValues ] ,
86+ ) ;
87+
7988 // ========================== Values ==========================
8089 const mergedCheckedKeys = React . useMemo ( ( ) => {
8190 if ( ! checkable ) {
@@ -154,6 +163,10 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
154163 // eslint-disable-next-line react-hooks/exhaustive-deps
155164 } , [ searchValue ] ) ;
156165
166+ const nodeDisabled = useEvent ( ( node : DataNode ) => {
167+ return isOverMaxCount && ! memoRawValues . includes ( node [ fieldNames . value ] ) ;
168+ } ) ;
169+
157170 // ========================== Get First Selectable Node ==========================
158171 const getFirstMatchingNode = ( nodes : EventDataNode < any > [ ] ) : EventDataNode < any > | null => {
159172 for ( const node of nodes ) {
@@ -221,8 +234,9 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
221234 // >>> Select item
222235 case KeyCode . ENTER : {
223236 if ( activeEntity ) {
237+ const isNodeDisabled = nodeDisabled ( activeEntity . node ) ;
224238 const { selectable, value, disabled } = activeEntity ?. node || { } ;
225- if ( selectable !== false && ! disabled ) {
239+ if ( selectable !== false && ! disabled && ! isNodeDisabled ) {
226240 onInternalSelect ( null , {
227241 node : { key : activeKey } ,
228242 selected : ! checkedKeys . includes ( value ) ,
@@ -276,42 +290,43 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
276290 { activeEntity . node . value }
277291 </ span >
278292 ) }
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 >
315330 </ div >
316331 ) ;
317332} ;
0 commit comments