mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-05 23:46:28 +08:00
fix: Button with disabled
and type="link"
should not clickable (#30209)
close #30207
This commit is contained in:
parent
ca31a75d1b
commit
edb59bd2e8
@ -300,4 +300,15 @@ describe('Button', () => {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should not redirect when button is disabled', () => {
|
||||
const onClick = jest.fn();
|
||||
const wrapper = mount(
|
||||
<Button href="https://ant.design" onClick={onClick} disabled>
|
||||
click me
|
||||
</Button>,
|
||||
);
|
||||
wrapper.simulate('click');
|
||||
expect(onClick).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
@ -193,8 +193,10 @@ const InternalButton: React.ForwardRefRenderFunction<unknown, ButtonProps> = (pr
|
||||
React.useEffect(fixTwoCNChar, [buttonRef]);
|
||||
|
||||
const handleClick = (e: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement, 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<HTMLButtonElement | HTMLAnchorElement>)?.(e);
|
||||
|
Loading…
Reference in New Issue
Block a user