Reputation: 514
we are using react and ant design as the frontend tech. One thing I noticed in the ant design modal. When we put onCancel attr in the modal like the code below. This will allow us can close the modal by clicking the 'X' in the right corner but it will also allow closing modal by clicking anywhere outside the model. Is there a way to prevent this outside click action while keeping the 'X' action ? Thanks in advance
<Modal
visible={visible}
title="My modal"
onOk={handleOk}
onCancel={closeMyModal}
className='myModal'
>
Upvotes: 5
Views: 10861
Reputation: 117
According to Antd's documentation, you have two solutions:
If you use the <Modal>
in your component, you'd to set maskClosable={false}
. This prevents you from viewing the modal when you press outside the modal area.
You can check Modal.confirm()
as follows:
https://ant.design/components/modal/#components-modal-demo-confirm
Upvotes: 1
Reputation: 386
add
maskClosable = {false}
to prevent closing the modal dialog when the mask (area outside the modal) is clicked
<Modal
visible={visible}
title="My modal"
onOk={handleOk}
onCancel={closeMyModal}
className='myModal'
maskClosable={false}
>
Upvotes: 26