Skip to content
This repository was archived by the owner on Dec 3, 2024. It is now read-only.
This repository was archived by the owner on Dec 3, 2024. It is now read-only.

[Bug] ArgumentNullException after pressing 'backspace' key #300

@oruchreis

Description

@oruchreis

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't workingTriageIssue needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions