javascript - Reactjs - event.stopPropagation not working - Stack Overflow

I have a Post ponent which basically render's a card. If the post is clicked, then the URL should

I have a Post ponent which basically render's a card. If the post is clicked, then the URL should route to '/expand/'.

Now I have another ponent called DeleteTemplate which renders a button and clicking it render's a Modal.

Now, I have used this DeleteTemplate in my Post ponent.

Now, clicking the DeleteTemplate button is rendering the Modal. In the Modal if i select the Cancel option, the URL is getting routed to '/expand/' which shouldn't be happening.

I have a Post ponent which basically render's a card. If the post is clicked, then the URL should route to '/expand/'.

Now I have another ponent called DeleteTemplate which renders a button and clicking it render's a Modal.

Now, I have used this DeleteTemplate in my Post ponent.

Now, clicking the DeleteTemplate button is rendering the Modal. In the Modal if i select the Cancel option, the URL is getting routed to '/expand/' which shouldn't be happening.

Share Improve this question asked Jul 20, 2018 at 11:29 Sreekar MouliSreekar Mouli 1,4425 gold badges27 silver badges50 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

The click events of the buttons in your modal are bubbling up to the card. You need to add event.stopPropagation() to the onClick handlers of those buttons inside the modal.

So in your DeleteTemplate render function:

<Button color="secondary" onClick={this.cancel}>
    CANCEL
</Button>

with the cancel handler looking like this:

cancel(event) {
    event.stopPropagation();
    this.toggleModal();
}

Working example:

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744323173a4568520.html

相关推荐

  • javascript - Reactjs - event.stopPropagation not working - Stack Overflow

    I have a Post ponent which basically render's a card. If the post is clicked, then the URL should

    8天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信