majorimi / blazor-components

Components collection and extensions for Blazor applications.
MIT License
327 stars 59 forks source link

Typeahead: Is there a way to unselect current item on focus? #115

Open toseni opened 2 years ago

toseni commented 2 years ago

Prerequisite: Have some item selected on TypeaheadInput.

When clicking on TypeaheadInput to focus it, TypeaheadInput leaves current item selected and places cursor at the end of item label.

Is there a way to change this behaviour, so that focus on TypeaheadInput would 1) unselect current item 2) clear search text 3) open dropdown?

majorimi commented 2 years ago

Hi @toseni,

Thanks for contacting me and sorry for the delay. I have tested Typeahead and at first was not able to reproduce your application behavior. Typeahead was opening the dropdown when it got focus.

But then reached the example "Typeahead async custom search method set to DataSource property as Func<string, Task<IEnumerable>>" Do you use this?

Because in this case data source is the result of an async method (e.g. server response). Opening the popup requires the search method to return values. It would not be optimal. And even yourself was mentioning 3 different behaviors. So it would be hard to decide which one is best for everyone.

For now what you might can do is to use IEnumerable<TItem> Data not the async DataSource by getting your values on component init, etc.

Later what I can do and the simplest is to expose OnFocus EventCallback which you can subscribe and trigger your on behavior. So if you wish you can trigger a new search, clear value, etc...