diff --git a/components/modal/ActionButton.tsx b/components/modal/ActionButton.tsx index c3f8c7a731..cdf6ec3f3d 100644 --- a/components/modal/ActionButton.tsx +++ b/components/modal/ActionButton.tsx @@ -12,18 +12,17 @@ export interface ActionButtonProps { } export interface ActionButtonState { - loading: boolean; + loading: ButtonProps['loading']; } export default class ActionButton extends React.Component { timeoutId: number; - constructor(props: ActionButtonProps) { - super(props); - this.state = { - loading: false, - }; - } + clicked: boolean; + + state = { + loading: false, + }; componentDidMount() { if (this.props.autoFocus) { @@ -38,6 +37,10 @@ export default class ActionButton extends React.Component { const { actionFn, closeModal } = this.props; + if (this.clicked) { + return; + } + this.clicked = true; if (actionFn) { let ret; if (actionFn.length) { @@ -62,6 +65,7 @@ export default class ActionButton extends React.Component + ); diff --git a/components/modal/__tests__/confirm.test.js b/components/modal/__tests__/confirm.test.js index 17e4d08971..478f5c50ea 100644 --- a/components/modal/__tests__/confirm.test.js +++ b/components/modal/__tests__/confirm.test.js @@ -231,4 +231,13 @@ describe('Modal.confirm triggers callbacks correctly', () => { ); warnSpy.mockRestore(); }); + + it('ok button should trigger onOk once when click it many times quickly', () => { + const onOk = jest.fn(); + open({ onOk }); + // Fifth Modal + $$('.ant-btn-primary')[0].click(); + $$('.ant-btn-primary')[0].click(); + expect(onOk).toHaveBeenCalledTimes(1); + }); });