prevent ant design modal outside clicking closing modal

Viewed 3472

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'
        >
3 Answers

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}
  >

You need to set property maskClosable by false to prevent it

Related