rob-balfre / svelte-select

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

V5 creatable removed #461

Closed quasarchimaere closed 1 year ago

quasarchimaere commented 1 year ago

it makes sense to let the user decide to implement the create method themselves... however: in your migration guide you show the example of using an on:click handler within the empty slot. although this is probably an easy example it does not cover the case where one would want to create an item that would have existing results... and thus it would be necessary to either add the create item to the items array temporarily whenever the filterText changes, or to use the list slot altogether and reimplement the standard behaviour + an entry with the item to create.

Example: list contains ["abcd", "abcde", "abcdef"] as values, so it is not really easy to create an "abc" element with the given migration example, you'd have to have a lot of boiler plate code.

i would suggest to add a create slot (which would be visible within the empty list as well as a list of items)

rob-balfre commented 1 year ago

@quasarchimaere good point. How about prepend-list and append-list named slots?

quasarchimaere commented 1 year ago

@quasarchimaere good point. How about prepend-list and append-list named slots?

@rob-balfre prepend-list and append-list slots seem to do the trick since they would also work for other usecases as well. even though i do not know the implementation details yet i am not sure how to handle the (keyboard) based selection of an item within these slots yet, do you think it would be possible to flag these slots in a way that they appear/are treated as part of the list aka an item itself -> that way one could key up/down on it and select with tab and enter as well as clicks

rob-balfre commented 1 year ago

@quasarchimaere I'd prefer in that scenario that we add to prop items.

For example, use filterText prop and an event like on:filter (we'd need to add that) that returned the filtered items.

The only way to achieve this currently is: https://svelte.dev/repl/0ed68d45d0334ab3969e4d1d0b5049bc?version=3.49.0 I don't like the bind:this, getFilteredItems and await tick() though, way way too much boilerplate. But adding on:filter should clean all that up.

What you think?

quasarchimaere commented 1 year ago

@rob-balfre on:filter sounds great to me, also thx for the repro/workaround provided, i might use that for the time being.