Skip to content

Breaking change in 0.4.9: clicking the container closes the modal #490

@robinmetral

Description

@robinmetral

Hi,

First, thanks a lot for this library!

Just wanted to report that 32140dd (released in 0.4.9) introduced a major breaking change:

Screen.Recording.2021-12-12.at.16.19.01.mov

Note: I'm running the docs locally in this recording. You can't see it in the deployed version, which I assume is running an older version of Micromodal.

🐛 What the issue is

The bug is in this onClick method:

https://github.com/ghosh/Micromodal/blob/a55c5fd2b64250f4569ba068b24001c3e7ac6d4e/lib/src/index.js#L135-L144

Line 138 (newly added) is the problem here, since most modals will follow the demo markup and look like this:

<div id="modal-1" aria-hidden="true">
  <div class="modal__overlay" tabindex="-1" data-micromodal-close>
    <div class="modal__container" role="dialog" aria-modal="true">
      <!-- content -->
    </div>
  </div>
</div>

Any click event on the container (for example its padding, or between children elements) will effectively close the modal because the container's parent (e.target.parentNode) is the overlay—which has the closeTrigger.

Reproducing

  1. clone the repo
  2. yarn
  3. yarn lib:build (make sure the latest lib is used by the docs)
  4. yarn docs:dev (run the docs)
  5. try to click the container, notice the bug

I'm happy to submit a PR to fix this, but I don't have context on why this change was applied in the first place1. Can we just remove this line? Or were you trying to fix something else with it?

Footnotes

  1. The changelog says 🐞 BUGFIX Correctly closes modal when clicking on nested close elements, which I don't really understand without context

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmedBug is has been confirmed and is reproducible

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions