rob-balfre / svelte-select

Svelte Select. A select component for Svelte
https://svelte-select-examples.vercel.app
Other
1.25k stars 175 forks source link

on:hoverItem isn't called when there is only one item #512

Closed joepetrakovich closed 1 year ago

joepetrakovich commented 1 year ago

I was expecting hoverItem to be called when I hover any item but it doesn't work if you only have one item. I'm assuming because the hoverIndex defaults to the first item.

Is there any way around that? I'd like the event to fire whenever an item is hovered.

<script>
    let items = ['One'];
</script>

<Select {items} on:hoverItem={(e) => {console.log(e)}} />
rob-balfre commented 1 year ago

You can create your own hover event in the item named slot. That should work

On Wed, 4 Jan 2023, 12:55 pm Joe Petrakovich, @.***> wrote:

I was expecting hoverItem to be called when I hover any item but it doesn't work if you only have one item. I'm assuming because the hoverIndex defaults to the first item.

Is there any way around that? I'd like the event to fire whenever an item is hovered.

<Select {items} on:hoverItem={(e) => {console.log(e)}} />

— Reply to this email directly, view it on GitHub https://github.com/rob-balfre/svelte-select/issues/512, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUAM7SE55IQJSRY27ZCS7TWQTKBRANCNFSM6AAAAAATQI2Q6Y . You are receiving this because you are subscribed to this thread.Message ID: @.***>

joepetrakovich commented 1 year ago

That'll work. I assume you mean via mouseenter/mouseleave events on the slot?

rob-balfre commented 1 year ago

yeah and a focus event.

joepetrakovich commented 1 year ago

Got it! Thanks for the idea, that'll work perfectly.