diff --git a/src/utils/valueUtil.ts b/src/utils/valueUtil.ts
index b414b409..0063ce82 100644
--- a/src/utils/valueUtil.ts
+++ b/src/utils/valueUtil.ts
@@ -32,10 +32,9 @@ export function getAllKeys(treeData: DefaultOptionType[], fieldNames: InternalFi
function dig(list: DefaultOptionType[]) {
list.forEach(item => {
- keys.push(item[fieldNames.value]);
-
const children = item[fieldNames.children];
if (children) {
+ keys.push(item[fieldNames.value]);
dig(children);
}
});
diff --git a/tests/Select.SearchInput.spec.js b/tests/Select.SearchInput.spec.js
index 3b6861c3..2cb3e061 100644
--- a/tests/Select.SearchInput.spec.js
+++ b/tests/Select.SearchInput.spec.js
@@ -1,5 +1,5 @@
/* eslint-disable no-undef */
-import React from 'react';
+import React, { useEffect, useState } from 'react';
import { mount } from 'enzyme';
import TreeSelect, { TreeNode } from '../src';
@@ -72,4 +72,98 @@ describe('TreeSelect.SearchInput', () => {
search('');
expect(listProps().expandedKeys).toEqual(['bamboo', 'light']);
});
+
+ it('not trigger loadData when clearing the search', () => {
+ let called = 0;
+ const handleLoadData = jest.fn();
+ const Demo = () => {
+ const [value, setValue] = useState();
+ const [treeData, setTreeData] = useState([]);
+
+ const addDefaultTreeData = () => {
+ setTreeData([
+ { id: 1, pId: 0, value: '1', title: 'Expand to load' },
+ { id: 2, pId: 0, value: '2', title: 'Expand to load' },
+ { id: 3, pId: 0, value: '3', title: 'Tree Node', isLeaf: true },
+ ])
+ }
+
+ const genTreeNode = (parentId, isLeaf = false) => {
+ const random = Math.random().toString(36).substring(2, 6);
+ return {
+ id: random,
+ pId: parentId,
+ value: random,
+ title: isLeaf ? 'Tree Node' : 'Expand to load',
+ isLeaf,
+ };
+ };
+
+ const onLoadData = ({ id, ...rest }) =>
+ new Promise((resolve) => {
+ setTimeout(() => {
+ called += 1;
+ handleLoadData({ id, ...rest });
+ setTreeData(
+ treeData.concat([
+ genTreeNode(id, false),
+ genTreeNode(id, true),
+ genTreeNode(id, true),
+ ])
+ );
+ resolve(undefined);
+ }, 300);
+ });
+
+ const onChange = (newValue) => {
+ setValue(newValue);
+ };
+
+ return (
+ <>
+