Close modal Ant Design with ESC

Asked

Viewed 120 times

-1

I need to close an Ant Design modal with ESC. I am using React. I have this function that closes the modal, but I’m having difficulties to implement in the code. Can you help me?

handleOk = (e) => {
    this.setState({
      visible: false,
    });
  }

1 answer

0


This behavior should be occurring by default, make sure you are not passing prop Keyboard false, if you are you can omit or pass it as true.

According to the documentation:

Keyboard:Boolean -> Whether support press Esc to close. Default value: true

    <Modal
      keyboard
      title="Basic Modal"
      visible={this.state.visible}
      onOk={this.handleOk}
      onCancel={this.handleCancel}
      okButtonProps={{ disabled: true }}
      cancelButtonProps={{ disabled: true }}
    >
      <p>Some contents...</p>
      <p>Some contents...</p>
      <p>Some contents...</p>
    </Modal>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.