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

Add a prop to determinate if filterText should be cleared after selection #677

Open alexfranco90 opened 2 months ago

alexfranco90 commented 2 months ago

Hi,

right now the value in filterText is cleared after a selection but it can be usefull, expecially in multi-selection mode, to not clear the current filter so users can select multiple items from list without the need of re-typing the filter. I propose to add a new prop, similar to clearFilterTextOnBlur, to determine if clearing or not the value in filterText when a selection happens.

In this moment the clearing of the filter happen in L493 https://github.com/rob-balfre/svelte-select/blob/244e5bb73a88db7fa5b9ee26206b4c388d2abcce/src/lib/Select.svelte#L493

I think it is enough to add a check at this point in the code based on a "prop" to determine the desired behavior. Similar to how it is already done during blur event.

Right now, I'm working around this issues by binding filterText and automatically set the previous value when the library try to clear it. But it's not a clean solution because it triggers multiple changes to the underling list and a flickering of the items in the list.

If you want I can open a PR for this.