[] => {
- return nodes.map(node => ({
- ...node,
- disabled:
- isOverMaxCount && !displayValues?.some(v => v.value === node[fieldNames.value])
- ? true
- : node.disabled,
- children: node.children ? traverse(node.children) : undefined,
- }));
- };
-
- const processedTreeData = React.useMemo(
- () => traverse(memoTreeData),
- [memoTreeData, isOverMaxCount],
- );
-
// ========================== Render ==========================
- if (processedTreeData.length === 0) {
+ if (memoTreeData.length === 0) {
return (
{notFoundContent}
@@ -304,7 +288,7 @@ const OptionList: React.ForwardRefRenderFunction = (_,
ref={treeRef}
focusable={false}
prefixCls={`${prefixCls}-tree`}
- treeData={processedTreeData}
+ treeData={memoTreeData}
height={listHeight}
itemHeight={listItemHeight}
itemScrollOffset={listItemScrollOffset}
diff --git a/src/TreeSelect.tsx b/src/TreeSelect.tsx
index a356d016..4419e23f 100644
--- a/src/TreeSelect.tsx
+++ b/src/TreeSelect.tsx
@@ -613,17 +613,33 @@ const TreeSelect = React.forwardRef((props, ref)
});
// ========================== Context ===========================
- const treeSelectContext = React.useMemo(() => {
- const isOverMaxCount =
- mergedMultiple && maxCount !== undefined && cachedDisplayValues?.length >= maxCount;
+ const isOverMaxCount =
+ mergedMultiple && maxCount !== undefined && cachedDisplayValues?.length >= maxCount;
+
+ const traverse = (nodes: DataNode[]): DataNode[] => {
+ return nodes.map(node => ({
+ ...node,
+ disabled:
+ isOverMaxCount && !cachedDisplayValues?.some(v => v.value === node.value)
+ ? true
+ : node.disabled,
+ children: node.children ? traverse(node.children) : undefined,
+ }));
+ };
+ const processedTreeData = React.useMemo(
+ () => traverse(filteredTreeData),
+ [filteredTreeData, isOverMaxCount],
+ );
+
+ const treeSelectContext = React.useMemo(() => {
return {
virtual,
dropdownMatchSelectWidth,
listHeight,
listItemHeight,
listItemScrollOffset,
- treeData: filteredTreeData,
+ treeData: processedTreeData,
fieldNames: mergedFieldNames,
onSelect: onOptionSelect,
treeExpandAction,
@@ -638,7 +654,7 @@ const TreeSelect = React.forwardRef((props, ref)
listHeight,
listItemHeight,
listItemScrollOffset,
- filteredTreeData,
+ processedTreeData,
mergedFieldNames,
onOptionSelect,
treeExpandAction,