Skip to content

Commit 16767e4

Browse files
committed
fix(Select): automatically clear searchValue
1 parent 3bfa108 commit 16767e4

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/Select.test.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,43 @@ describe('Select.Basic', () => {
7676
expectOpen(container);
7777
});
7878

79+
it('should not clear searchValue', () => {
80+
const App: React.FC = () => {
81+
const [options, setOptions] = React.useState<{ label: string; value: string }[]>([]);
82+
const [isFetching, setIsFetching] = React.useState<boolean>(false);
83+
84+
function handleSearch() {
85+
setIsFetching(true);
86+
setTimeout(() => {
87+
setOptions([]);
88+
setIsFetching(false);
89+
}, 1000);
90+
}
91+
92+
return (
93+
<Select
94+
style={{ width: 300 }}
95+
showSearch={{ filterOption: false, onSearch: handleSearch }}
96+
placeholder="Type to search users..."
97+
loading={isFetching}
98+
options={options}
99+
notFoundContent={isFetching ? 'Loading...' : null}
100+
/>
101+
);
102+
};
103+
const { container } = render(<App />);
104+
const searchInput = container.querySelector('input') as HTMLInputElement;
105+
expect(searchInput).toBeTruthy();
106+
expect(searchInput.value).toBe('');
107+
fireEvent.change(searchInput, { target: { value: 'user query' } });
108+
expect(searchInput.value).toBe('user query');
109+
act(() => {
110+
jest.advanceTimersByTime(1000);
111+
});
112+
expect(searchInput.value).toBe('user query');
113+
jest.useRealTimers();
114+
});
115+
79116
describe('render', () => {
80117
function genSelect(props?: Partial<SelectProps>) {
81118
return (
@@ -1058,6 +1095,7 @@ describe('Select.Basic', () => {
10581095
);
10591096
}
10601097
}
1098+
10611099
const { container } = render(<Controlled />);
10621100
expectOpen(container);
10631101
toggleOpen(container);

0 commit comments

Comments
 (0)