2

I'm using Ant Design and React js for my Project.

Problem

I have a button in Popover and having click event for that button. The problem is button click event is not triggering.

JS Code

const content = (
  <div className="RecurringPopover"> 
    <button onClick={this.handleClick}> Popover Button </button> 
  </div>
);

Full Code with scenario in stackblitz

k.s.
  • 2,964
  • 1
  • 25
  • 27
Maria Jeysingh Anbu
  • 3,164
  • 3
  • 34
  • 55

2 Answers2

2

You have defined content outside the class and then supplying this.handleClick as a click handler to it. However outside class, this does not point to the class. You should define content inside class and use this.content to access that.

handleClick() {
      alert('test');
    }
// put it inside class
 content = (
  <div className="RecurringPopover"> 
    <button onClick={this.handleClick}> Popover Button </button> 
  </div>
);
  render() {
    return (
      <div>
        <Row>
          <Col span={12}>      
          // Use this.content instead of just content
          <Popover content={this.content} title="Title">
            <span type="primary">Hover me (Popover Button)</span>
Prakash Sharma
  • 15,542
  • 6
  • 30
  • 37
0

Just bring the 'content' to inside the class, and pass it to component via 'this.content', it will work.

Acauã Pitta
  • 654
  • 1
  • 9
  • 16