Skip to content

Close the modal window on the first click when using stopPropagation() #1035

@pavelgromyko

Description

@pavelgromyko

I understand that such questions have already been encountered, but I still haven’t found a solution for my case. I will be grateful to the community for help.

I'm using ReactModal to create a modal window in component MenuModal (parent) . The modal window contains cards with information about products (Card (child) component). The Card component has onClick={(e) => {e.stopPropagation();}} (to call a submenu) which does not allow close the modal window the first time (only the second).

Current Behavior

  1. You click on the "Open Modal" button
  2. In the modal window, click on the phrase "Some Text"
  3. Move the cursor outside the modal window and click (to close the modal window). But there is no closure.
  4. Click the cursor a second time and the modal window closes

Expected behavior:

Close modal window on first click

Real example

Here is a simplified code, but the gist is clear.
https://codesandbox.io/p/sandbox/magical-dawn-tztk55

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions