Skip to content

Commit 667dc46

Browse files
committed
chore: handle git conflicts manually
1 parent 06dee72 commit 667dc46

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

src/OptionList.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,6 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
158158

159159
// >>> Disabled Strategy
160160
const disabledStrategy = (node: DataNode) => {
161-
// if (node.disabled) {
162-
// return true;
163-
// }
164-
165161
if (isOverMaxCount) {
166162
const selectedValues = displayValues?.map(v => v.value) || [];
167163
if (!selectedValues.includes(node[fieldNames.value])) {
@@ -309,13 +305,15 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
309305
onKeyUp: () => {},
310306
}));
311307

312-
const loadDataFun = useMemo(
313-
() => (searchValue ? null : (loadData as any)),
308+
const hasLoadDataFn = useMemo(
309+
() => (searchValue ? false : true),
314310
[searchValue, treeExpandedKeys || expandedKeys],
315311
([preSearchValue], [nextSearchValue, nextExcludeSearchExpandedKeys]) =>
316312
preSearchValue !== nextSearchValue && !!(nextSearchValue || nextExcludeSearchExpandedKeys),
317313
);
318314

315+
const syncLoadData = hasLoadDataFn ? loadData : null;
316+
319317
const onActiveChange = (key: Key) => {
320318
if (!isOverMaxCount) {
321319
setActiveKey(key);
@@ -364,7 +362,7 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
364362
showIcon={showTreeIcon}
365363
switcherIcon={switcherIcon}
366364
showLine={treeLine}
367-
loadData={loadDataFun}
365+
loadData={syncLoadData}
368366
motion={treeMotion}
369367
activeKey={activeKey}
370368
// We handle keys by out instead tree self

tests/Select.loadData.spec.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* eslint-disable no-undef, react/no-multi-comp, no-console */
2+
import React from 'react';
3+
import { render, fireEvent, act } from '@testing-library/react';
4+
5+
import TreeSelect from '../src';
6+
7+
describe('TreeSelect.loadData', () => {
8+
it('keep sync', async () => {
9+
const Demo = () => {
10+
const [treeData, setTreeData] = React.useState([
11+
{
12+
title: '0',
13+
value: 0,
14+
isLeaf: false,
15+
},
16+
]);
17+
18+
const loadData = async () => {
19+
const nextId = treeData.length;
20+
21+
setTreeData([
22+
...treeData,
23+
{
24+
title: `${nextId}`,
25+
value: nextId,
26+
isLeaf: false,
27+
},
28+
]);
29+
};
30+
31+
return <TreeSelect open treeData={treeData} loadData={loadData} />;
32+
};
33+
34+
render(<Demo />);
35+
36+
for (let i = 0; i < 5; i += 1) {
37+
fireEvent.click(document.querySelector('.rc-tree-select-tree-switcher_close'));
38+
await act(async () => {
39+
await Promise.resolve();
40+
});
41+
expect(
42+
document.querySelectorAll('.rc-tree-select-tree-list .rc-tree-select-tree-treenode'),
43+
).toHaveLength(2 + i);
44+
}
45+
});
46+
});

0 commit comments

Comments
 (0)