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 |
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 |
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|stopPropagationto 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.