Description
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:
- Open the provided code sandbox: https://codesandbox.io/s/react-modal-layout-issue-xgfsvk
- Click on the "Open Modal" button to open the first modal.
- Click on the icon in the top left corner of the first modal to open the second modal.
- Close the second modal by clicking on the overlay or close button.
- 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:
- Open the provided code sandbox: https://codesandbox.io/s/react-modal-layout-issue-xgfsvk
- Click on the "Open Modal" button to open the first modal.
- Click on the icon in the top right corner of the first modal to close it.
- Click on the "Open Modal" button again to open the first modal.
- Attempt to close the first modal by clicking on the overlay.