From edb59bd2e892d24c4e19cfeace8cd2435486e673 Mon Sep 17 00:00:00 2001 From: afc163 Date: Mon, 19 Apr 2021 17:19:22 +0800 Subject: [PATCH] fix: Button with `disabled` and `type="link"` should not clickable (#30209) close #30207 --- components/button/__tests__/index.test.tsx | 11 +++++++++++ components/button/button.tsx | 6 ++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/components/button/__tests__/index.test.tsx b/components/button/__tests__/index.test.tsx index 944ce28fff..cb20998415 100644 --- a/components/button/__tests__/index.test.tsx +++ b/components/button/__tests__/index.test.tsx @@ -300,4 +300,15 @@ describe('Button', () => { }, }); }); + + it('should not redirect when button is disabled', () => { + const onClick = jest.fn(); + const wrapper = mount( + , + ); + wrapper.simulate('click'); + expect(onClick).not.toHaveBeenCalled(); + }); }); diff --git a/components/button/button.tsx b/components/button/button.tsx index fe86a35883..4a8a2b4566 100644 --- a/components/button/button.tsx +++ b/components/button/button.tsx @@ -193,8 +193,10 @@ const InternalButton: React.ForwardRefRenderFunction = (pr React.useEffect(fixTwoCNChar, [buttonRef]); const handleClick = (e: React.MouseEvent) => { - const { onClick } = props; - if (innerLoading) { + const { onClick, disabled } = props; + // https://github.com/ant-design/ant-design/issues/30207 + if (innerLoading || disabled) { + e.preventDefault(); return; } (onClick as React.MouseEventHandler)?.(e);