Typeahead icon indicating copy to clipboard operation
Typeahead copied to clipboard

[Bug] ArgumentNullException after pressing 'backspace' key

Open oruchreis opened this issue 2 years ago • 0 comments

Describe the bug If we type a few letter less than MinimumLength and IsMultiselect is true, we get ArgumentNullException after clearing text by pressing backspace key. This error occurs when the MinimumLength property is set and the search metod is not triggered because of count of letters is not reached MinimumLength yet, and backspace key is used for clearing.

      System.ArgumentNullException: Value cannot be null. (Parameter 'source')
         at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
         at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
         at Blazored.Typeahead.BlazoredTypeahead`2.HandleKeyup(KeyboardEventArgs args)
         at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
         at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

To Reproduce

  • Add these to a page
<BlazoredTypeahead TItem="string" TValue="string"
                   AddItemOnEmptyResultMethod="AddNewAsync"
                   SearchMethod="Search" @bind-Values="_values"
                   MinimumLength="3">
    <SelectedTemplate>@context</SelectedTemplate>
    <ResultTemplate>@context</ResultTemplate>
</BlazoredTypeahead>
@code {
    private IList<string>? _values { get; set; }

    private Task<IEnumerable<string>> Search(string? searchText)
    {
        return Task.FromResult(Array.Empty<string>().AsEnumerable());
    }

    public Func<string, Task<string>> AddNewAsync { get; set; } = (newValue) => Task.FromResult(newValue);
}
  • Be sure nullable is enable
  • Run the app
  • Type a letter and press backspace key to delete it.

Hosting Model (is this issue happening with a certain hosting model?):

  • Blazor Server

Version: 4.7.0

oruchreis avatar Dec 07 '22 10:12 oruchreis