CaptainCodeman / svelte-headlessui

HeadlessUI components for Svelte
https://captaincodeman.github.io/svelte-headlessui/
MIT License
539 stars 26 forks source link

Ability to add something other than button behavior in the "menu"? #10

Closed saturnonearth closed 1 year ago

saturnonearth commented 1 year ago

I want to change the menu dropdown buttons to trigger a form, and another to be an anchor link, but the current implementation does not allow it. It seems to disable any events on that actual menu item in order to file the custom event.

CaptainCodeman commented 1 year ago

Can you post a code snippet of what you mean? I tried adding an on:click handler directly to the buttons here and that seems to work, so I'm probably not fully understanding what you're describing.

saturnonearth commented 1 year ago

<a use:menu.item class="w-full flex items-center" href={option.href(id)}> <Icon src={option.icon} theme="outline" width="20" height="20" class="flex-shrink-0 mr-2 h-5 w-5" />{option.text}</a> Snap

The custom event on the use:menu.item prevents anything from actually running within the button itself. If you put a form button there, it will not actually submit the form.

For instance, this will not submit a form. <button type="submit" form="deleteItem" use:menu.item>Submit</button>

CaptainCodeman commented 1 year ago

Ah, I see - I probably just need to remove the .preventDefault() that get's added. I'll check that doesn't affect anything, I don't think it would. It should then also allow you to use the different menu options as different form submit actions.

saturnonearth commented 1 year ago

Sadly it appears to still be blocked somehow.

CaptainCodeman commented 1 year ago

Sorry, I haven't had chance to publish it yet :)

saturnonearth commented 1 year ago

haha oops 🤦

CaptainCodeman commented 1 year ago

No worries, should be there now.