A free and open-source web framework that enables developers to create web apps using C# and HTML, developed by Microsoft.
My solution is trying to add the user input (if not found in the dropdown) to the result of the OnComboSearch(string value). User then can select his/her own input from the dropdown.
The following is my own search function
private async Task<IEnumerable<DropdownOption>> Search(string searchText, CancellationToken token)
{
// use an asynchronous function for fetching data from an api.
HashSet<DropdownOption> _found = new();
await Task.Delay(1, token);
// if searchText is null or empty, show complete list
if (string.IsNullOrEmpty(searchText))
{
_found = _dropdownList;
}
// otherwise, filtered list
_found = _dropdownList.Where(x => x.Text.Contains(searchText, StringComparison.InvariantCultureIgnoreCase) ).ToHashSet();
Console.WriteLine($"Found: {_found.Count()}");
if (_found.Count() == 0)
{ // add user's own input as a new dropdownOption
_found.Add(new DropdownOption { Text = searchText, Value = searchText });
}
return _found;
}