Closed jnysteen closed 2 years ago
Thanks for reporting this issue. May I ask why the <form />
element is wrapping <Modal />
? When the <form />
element is inside Popup.svelte
the problem does not appear. I am asking because I am have a hard time understanding the current use case here.
Apart from that, your fix seems to make sense to me, so I am happy to add it.
Demo with fix: https://svelte.dev/repl/7e3efb8138314975ad246a3a575a450b?version=3.48.0
Do you want to submit a PR with this fix? Otherwise I can also add it real quick.
@jnysteen I took the liberty to turn your branch into a PR: https://github.com/flekschas/svelte-simple-modal/pull/84
Fixed via #84
Just released v1.4.1 which contains the fix. Thanks again for reporting and fixing the issue!
First of all, thanks for a great library!
I have identified an issue: If a modal is contained within a form, the form is submitted when the close button on the modal is clicked.
Here is a Svelte REPL that shows the issue - notice how "submitted" is logged to the console, when the close button is clicked. https://svelte.dev/repl/dd87925ed7a64f08936257414fd63841?version=3.48.0
This behaviour can cause unintended form submissions.
I'll create a PR with a fixI will not create a PR as I currently can't properly test if this change will fix it - but if I inspect the rendered HTML, add this change, and then click the close button, the form is not submitted. The change can be found here: https://github.com/flekschas/svelte-simple-modal/compare/master...jnysteen:master