Skip to content

Commit c69fcae

Browse files
committed
refactor: use InternalContext
1 parent 7df686a commit c69fcae

File tree

3 files changed

+144
-79
lines changed

3 files changed

+144
-79
lines changed

src/OptionList.tsx

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useBaseProps } from 'rc-select';
22
import type { RefOptionListProps } from 'rc-select/lib/OptionList';
33
import type { TreeProps } from 'rc-tree';
44
import Tree from 'rc-tree';
5+
import { InternalContext } from 'rc-tree';
56
import type { EventDataNode, ScrollTo } from 'rc-tree/lib/interface';
67
import KeyCode from 'rc-util/lib/KeyCode';
78
import useMemo from 'rc-util/lib/hooks/useMemo';
@@ -158,8 +159,7 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
158159
// eslint-disable-next-line react-hooks/exhaustive-deps
159160
}, [searchValue]);
160161

161-
// >>> Disabled Strategy
162-
const disabledStrategy = (node: DataNode) => {
162+
const nodeDisabled = (node: DataNode) => {
163163
if (isOverMaxCount) {
164164
const selectedValues = memoDisplayValues;
165165
if (!selectedValues.includes(node[fieldNames.value])) {
@@ -342,43 +342,43 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
342342
{activeEntity.node.value}
343343
</span>
344344
)}
345-
346-
<Tree
347-
ref={treeRef}
348-
focusable={false}
349-
prefixCls={`${prefixCls}-tree`}
350-
treeData={memoTreeData}
351-
height={listHeight}
352-
itemHeight={listItemHeight}
353-
itemScrollOffset={listItemScrollOffset}
354-
virtual={virtual !== false && dropdownMatchSelectWidth !== false}
355-
multiple={multiple}
356-
icon={treeIcon}
357-
showIcon={showTreeIcon}
358-
switcherIcon={switcherIcon}
359-
showLine={treeLine}
360-
loadData={syncLoadData}
361-
motion={treeMotion}
362-
activeKey={activeKey}
363-
// We handle keys by out instead tree self
364-
checkable={checkable}
365-
checkStrictly
366-
checkedKeys={mergedCheckedKeys}
367-
selectedKeys={!checkable ? checkedKeys : []}
368-
defaultExpandAll={treeDefaultExpandAll}
369-
titleRender={treeTitleRender}
370-
{...treeProps}
371-
// Proxy event out
372-
onActiveChange={setActiveKey}
373-
onSelect={onInternalSelect}
374-
onCheck={onInternalSelect}
375-
onExpand={onInternalExpand}
376-
onLoad={onTreeLoad}
377-
filterTreeNode={filterTreeNode}
378-
expandAction={treeExpandAction}
379-
onScroll={onPopupScroll}
380-
disabledStrategy={disabledStrategy}
381-
/>
345+
<InternalContext.Provider value={{ nodeDisabled }}>
346+
<Tree
347+
ref={treeRef}
348+
focusable={false}
349+
prefixCls={`${prefixCls}-tree`}
350+
treeData={memoTreeData}
351+
height={listHeight}
352+
itemHeight={listItemHeight}
353+
itemScrollOffset={listItemScrollOffset}
354+
virtual={virtual !== false && dropdownMatchSelectWidth !== false}
355+
multiple={multiple}
356+
icon={treeIcon}
357+
showIcon={showTreeIcon}
358+
switcherIcon={switcherIcon}
359+
showLine={treeLine}
360+
loadData={syncLoadData}
361+
motion={treeMotion}
362+
activeKey={activeKey}
363+
// We handle keys by out instead tree self
364+
checkable={checkable}
365+
checkStrictly
366+
checkedKeys={mergedCheckedKeys}
367+
selectedKeys={!checkable ? checkedKeys : []}
368+
defaultExpandAll={treeDefaultExpandAll}
369+
titleRender={treeTitleRender}
370+
{...treeProps}
371+
// Proxy event out
372+
onActiveChange={setActiveKey}
373+
onSelect={onInternalSelect}
374+
onCheck={onInternalSelect}
375+
onExpand={onInternalExpand}
376+
onLoad={onTreeLoad}
377+
filterTreeNode={filterTreeNode}
378+
expandAction={treeExpandAction}
379+
onScroll={onPopupScroll}
380+
/>
381+
</InternalContext.Provider>
382382
</div>
383383
);
384384
};

0 commit comments

Comments
 (0)