radzenhq / radzen-blazor

Radzen Blazor is a set of 90+ free native Blazor UI components packed with DataGrid, Scheduler, Charts and robust theming including Material design and FluentUI.

Home Page:https://www.radzen.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DropDownBase.cs virtualization=true configuration broken

ReinoutWW opened this issue · comments

Hello,

We are running into an issue with the Radzen DropDown. See below for details.

Thanks!

Describe the bug
We have an issue with the DropDown component virtualization option. DropDownBase.cs.

Once we press "enter" while focussing on the component, we will get a console error stating:

Error: System.ArgumentNullException: Value cannot be null. (Parameter 'source')
   at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
   at System.Linq.Enumerable.Count[TSource](IEnumerable'1 source)
   at Radzen.DropDownBase'1.HandleKeyPress(KeyboardEventArgs args, Boolean isFilter, Nullable'1 shouldSelectOnChange)
   at Radzen.DropDownBase'1.OnKeyPress(KeyboardEventArgs args, Nullable'1 shouldSelectOnChange)
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

We've inspected the code, and found the issue to be fixed once 'AllowVirtualization' was set to 'false', so it only appears on the AllowVirtualization=true. It seems like the virtual items list is null in the 'HandleKeyPress' method.

Maybe this helps as well
We've read the following code in 'DropDownBase.cs', within 'HandleKeyPress':

        List<object> items = Enumerable.Empty<object>().ToList();
        if (!base.LoadData.HasDelegate)
        {
            items = ((!IsVirtualizationAllowed()) ? View.Cast<object>().ToList() : virtualItems);
        }
        else if (Data != null)
        {
            items = Data.Cast<object>().ToList();
        }

With this knowledge, we've added an empty delegate to the LoadData parameter. This resulted in the else if to run, which resulted in the issue not occuring on screen. With this, we've got the feeling it must be somewhere in the 'virtualItems' list returning null.

It's with the following dropdown configuration:

  • AllowVirtualization=true (seems to start the issue)
  • AllowClear="false"
  • AllowFiltering="true"
  • TValue="IdStringDescr" //
  • TextProperty="@nameof(IdStringDescr.Description)" // String
  • FilterCaseSensitivity="Radzen.FilterCaseSensitivity.CaseInsensitive"
  • Data=@values //
  • @bind-Value="SelectedValue"
  • Change="@onchange"
  • Disabled=@disabled

// Adittional information

private List<IdStringDescr>? Values;

public class IdStringDescr
{
    public IdStringDescr()
    {
    }
    public IdStringDescr(string id, string description)
    {
        Id = id;
        Description = description;
    }
    public string Id { get; set; } = null!;
    public string Description { get; set; } = null!;
}

To Reproduce
Steps to reproduce the behavior:

  1. Go to a page with at least 2 stacked dropdowns in the UI
  2. Navigate with the 'tab' key, to the dropdown
  3. Then keypress 'enter', to open the dropdown with filter options + virtualization. The error will appear in the console. (unhandled exception )

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: Chrome