fix(Input.Search): pressing enter key don't trigger onSearch while loading (#38575) (#38578)

This commit is contained in:
JackLiR8 2022-11-15 18:40:04 +08:00 committed by GitHub
parent 5ef12dfaa5
commit 3c96997210
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -75,7 +75,7 @@ const Search = React.forwardRef<InputRef, SearchProps>((props, ref) => {
};
const onPressEnter = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (composedRef.current) {
if (composedRef.current || loading) {
return;
}
onSearch(e);

View File

@ -161,6 +161,15 @@ describe('Input.Search', () => {
expect(asFragmentWithEnterButton().firstChild).toMatchSnapshot();
});
it('should not trigger onSearch when press enter while loading', () => {
const onSearch = jest.fn();
const { container } = render(
<Search loading onSearch={onSearch} />,
);
fireEvent.keyDown(container.querySelector('input')!, { key: 'Enter', keyCode: 13 });
expect(onSearch).not.toHaveBeenCalled();
});
it('should support addonAfter and suffix for loading', () => {
const { asFragment } = render(<Search loading suffix="suffix" addonAfter="addonAfter" />);
const { asFragment: asFragmentWithEnterButton } = render(