Skip to content

Submit events propagates to other forms without the ability to prevent it #549

@felixmosh

Description

@felixmosh

I have a page with a main form, which uses onValidSubmit callback.
And a second sub form which is inside a modal (not related to the main form).

When I submit (via button) the modal form, the main form gets the submit event as well.
I've debugged it and found out that the issue is that the modal event form is propagated to the main one (this is how events works in React).

The problem is that I don't have the event in order to call stopPropagation on it.

https://codesandbox.io/s/fervent-dubinsky-pw99c?file=/src/App.tsx

Possible solution is to pass the submit event to the onValidSubmit/onInvalidSubmit/onSubmit as the last argument

More info, https://reactjs.org/docs/portals.html#event-bubbling-through-portals

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