Divs with on:click events prevent form submission #10989
-
In my current project, I've been building several UI components, including a dropdown menu. My code has worked as expected until I tried to use forms with it. Consider the following files: App.svelte
Base.svelte
Dropdown.svelte
When the submit button is clicked, only its on:click event is triggered and console will log "clicked". But if I remove the on:click event from the div on this line |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
The click Event fires before the submit Event. In that case your dropdown closes and the Form is removed from the dom. Try to add |
Beta Was this translation helpful? Give feedback.
The click Event fires before the submit Event. In that case your dropdown closes and the Form is removed from the dom. Try to add
on:click|stopPropagation
to the submit button.And also, does clicking in the Input also close the dropdown? I suggest passing down a close function using a slot prop to explicitly close the dropdown.