From 3c96997210f580bb8057948d3ce7d8cfdd3e0e59 Mon Sep 17 00:00:00 2001 From: JackLiR8 <45257542+JackLiR8@users.noreply.github.com> Date: Tue, 15 Nov 2022 18:40:04 +0800 Subject: [PATCH] fix(Input.Search): pressing enter key don't trigger `onSearch` while loading (#38575) (#38578) --- components/input/Search.tsx | 2 +- components/input/__tests__/Search.test.tsx | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/components/input/Search.tsx b/components/input/Search.tsx index 42e34abc43..aa247afef6 100644 --- a/components/input/Search.tsx +++ b/components/input/Search.tsx @@ -75,7 +75,7 @@ const Search = React.forwardRef((props, ref) => { }; const onPressEnter = (e: React.KeyboardEvent) => { - if (composedRef.current) { + if (composedRef.current || loading) { return; } onSearch(e); diff --git a/components/input/__tests__/Search.test.tsx b/components/input/__tests__/Search.test.tsx index a891512de4..bd771631c2 100644 --- a/components/input/__tests__/Search.test.tsx +++ b/components/input/__tests__/Search.test.tsx @@ -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( + , + ); + fireEvent.keyDown(container.querySelector('input')!, { key: 'Enter', keyCode: 13 }); + expect(onSearch).not.toHaveBeenCalled(); + }); + it('should support addonAfter and suffix for loading', () => { const { asFragment } = render(); const { asFragment: asFragmentWithEnterButton } = render(