blazor-components icon indicating copy to clipboard operation
blazor-components copied to clipboard

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

Open toseni opened this issue 2 years ago • 1 comments

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?

toseni avatar May 12 '22 09:05 toseni

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<StatesWithFlags>>>" 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...

majorimi avatar May 30 '22 19:05 majorimi