Skip to content

Commit 8d63a07

Browse files
committed
feat: sync disabled state
1 parent aa28c56 commit 8d63a07

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/OptionList.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
8282
[checkedKeys, maxCount, multiple],
8383
);
8484

85+
const traverse = (nodes: EventDataNode<any>[]): EventDataNode<any>[] => {
86+
return nodes.map(node => ({
87+
...node,
88+
disabled: isOverMaxCount && !checkedKeys.includes(node.key as SafeKey) ? true : node.disabled,
89+
children: node.children ? traverse(node.children) : undefined,
90+
}));
91+
};
92+
93+
const processedTreeData = React.useMemo(
94+
() => traverse(memoTreeData),
95+
[memoTreeData, isOverMaxCount, checkedKeys],
96+
);
97+
8598
// ========================== Active ==========================
8699
const [activeKey, setActiveKey] = React.useState<Key>(null);
87100
const activeEntity = keyEntities[activeKey as SafeKey];
@@ -252,7 +265,7 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
252265
ref={treeRef}
253266
focusable={false}
254267
prefixCls={`${prefixCls}-tree`}
255-
treeData={memoTreeData}
268+
treeData={processedTreeData}
256269
height={listHeight}
257270
itemHeight={listItemHeight}
258271
itemScrollOffset={listItemScrollOffset}
@@ -279,7 +292,6 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
279292
onCheck={onInternalSelect}
280293
onExpand={onInternalExpand}
281294
onLoad={onTreeLoad}
282-
disabled={isOverMaxCount}
283295
filterTreeNode={filterTreeNode}
284296
expandAction={treeExpandAction}
285297
onScroll={onPopupScroll}

src/TreeSelect.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
564564
onDeselect,
565565
rawCheckedValues,
566566
rawHalfCheckedValues,
567+
maxCount,
567568
],
568569
);
569570

0 commit comments

Comments
 (0)