Search code examples
popoverantd

Antd Popover close only when click on a button


Here is sandbox Antd pop over

As you can see in the example when you click out side anywhere, popover automatically closed. I want to disable that thing and close it only through click on a button. I don't see such options in Popover and Tooltip apis. Is this possible?


Solution

  • For this you need to remove your onVisibleChange={this.handleVisibleChange} method. You can call this.handleVisibleChange function on button click as given below:

    <Popover
        content={<a onClick={this.hide}>Close</a>}
        title="Title"
        trigger="click"
        visible={this.state.visible}
      >
        <Button onClick={this.handleVisibleChange} type="primary">Click me</Button>
    </Popover>
    

    I have created a working example on codesandbox.io.