Chakra-ui: [Modal] Anchor link click closes modal

Created on 27 Mar 2020  路  3Comments  路  Source: chakra-ui/chakra-ui

Describe the bug
Clicking on an anchor link inside a Modal causes it to close. On further inspection, I detected that clicking the link calls Modal's onClose with the identifier _clickedOverlay_

Expected Behavior
Clicking an anchor link should not call _clickedOverlay_ event, and thus not close the Modal.

To Reproduce

  1. Use this Code:
<Modal isOpen={true} onClose={console.log}>
        <ModalOverlay />
        <ModalContent>
            <a href="#">Secondary Action</a>
        </ModalContent>
 </Modal>
  1. Click link
  2. Check logs for _clickedOverlay_ event

Suggested solution(s)
I checked the code and it seems that the overlay (which throws _clickedOverlay_ event) is a parent of the Modal content, and somehow the click event on the anchor link is not prevented from bubbling up to this overlay. Maybe this should be a sibling of the content and not a parent. Although this could cause issues for the escape key mechanism.

Desktop (please complete the following information):

  • Linux
  • Chrome
  • 80.0

Additional context
This also happens in Drawer component, which inherits from Modal

Bug 馃悰

Most helpful comment

Hi @Machinezero,

Thanks for this issue. Your thoughts and recommended solutions are valid.

We've solved this in preparation for the next release.

All 3 comments

Hi @Machinezero,

Thanks for this issue. Your thoughts and recommended solutions are valid.

We've solved this in preparation for the next release.

Any update regarding this bug? I also faced this issue. Needed to call stopPropagation manually

This has been released in v1.0.0.rc-0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

callumflack picture callumflack  路  3Comments

ianstormtaylor picture ianstormtaylor  路  3Comments

nainardev picture nainardev  路  3Comments

harshzalavadiya picture harshzalavadiya  路  3Comments

polRk picture polRk  路  3Comments