Skip to content

Commit 73e9ae7

Browse files
committed
fix: fix some case
1 parent 142385a commit 73e9ae7

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/OptionList.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import LegacyContext from './LegacyContext';
1111
import TreeSelectContext from './TreeSelectContext';
1212
import type { DataNode, Key, SafeKey } from './interface';
1313
import { getAllKeys, isCheckDisabled } from './utils/valueUtil';
14+
import { useEvent } from 'rc-util';
1415

1516
const HIDDEN_STYLE = {
1617
width: 0,
@@ -79,7 +80,10 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
7980
(prev, next) => next[0] && prev[1] !== next[1],
8081
);
8182

82-
const memoDisplayValues = React.useMemo(() => displayValues?.map(v => v.value), [displayValues]);
83+
const memoDisplayValues = React.useMemo(
84+
() => (displayValues || []).map(v => v.value),
85+
[displayValues],
86+
);
8387

8488
// ========================== Values ==========================
8589
const mergedCheckedKeys = React.useMemo(() => {
@@ -154,21 +158,17 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
154158

155159
React.useEffect(() => {
156160
if (searchValue) {
157-
setSearchExpandedKeys(getAllKeys(memoTreeData, fieldNames));
161+
setSearchExpandedKeys(getAllKeys(treeData, fieldNames));
158162
}
159163
// eslint-disable-next-line react-hooks/exhaustive-deps
160164
}, [searchValue]);
161165

162-
const nodeDisabled = (node: DataNode) => {
163-
if (isOverMaxCount) {
164-
const selectedValues = memoDisplayValues;
165-
if (!selectedValues.includes(node[fieldNames.value])) {
166-
return true;
167-
}
166+
const nodeDisabled = useEvent((node: DataNode) => {
167+
if (isOverMaxCount && !memoDisplayValues.includes(node[fieldNames.value])) {
168+
return true;
168169
}
169-
170-
return undefined;
171-
};
170+
return false;
171+
});
172172

173173
// ========================== Get First Selectable Node ==========================
174174
const getFirstMatchingNode = (nodes: EventDataNode<any>[]): EventDataNode<any> | null => {

0 commit comments

Comments
 (0)