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);