Skip to content

Modal doesn't close on the first click on the overlay after click on elements containing event.stopPropagation() inside modal #1015

Open
@ErikDeviashin

Description

@ErikDeviashin

Summary:

When opening a second modal from within a first modal, closing the second modal results in the first modal not closing on the first click on the overlay. Instead, it requires a second click to close. This issue is similar to issue #958. However, the solution provided there is not really suitable for our cross-platform project, which uses components from react-native, and I would like to avoid creating separate button components for the web modal, in which event.stopPropagation() would be removed, in order to achieve the correct behavior.

Steps to reproduce:

  1. Open the provided code sandbox: https://codesandbox.io/s/react-modal-layout-issue-xgfsvk
  2. Click on the "Open Modal" button to open the first modal.
  3. Click on the icon in the top left corner of the first modal to open the second modal.
  4. Close the second modal by clicking on the overlay or close button.
  5. Attempt to close the first modal by clicking on the overlay.

Expected behavior:

The first modal should close after the first click on the overlay.

Link to example of issue:

https://codesandbox.io/s/react-modal-layout-issue-xgfsvk

Additional notes:

This issue also occurs when closing a modal by clicking on the close button, then reopening it and attempting to close it by clicking on the overlay. The modal only closes after the second click, not the first. This is a kind of standard behavior, so you can reproduce the problem for both the first and second modals. Below are the steps to reproduce the problem for the first modal.

Steps to reproduce:

  1. Open the provided code sandbox: https://codesandbox.io/s/react-modal-layout-issue-xgfsvk
  2. Click on the "Open Modal" button to open the first modal.
  3. Click on the icon in the top right corner of the first modal to close it.
  4. Click on the "Open Modal" button again to open the first modal.
  5. Attempt to close the first modal by clicking on the overlay.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions