Skip to content

fix: Selection Bugs after filtering Items in FluentListbox#5241

Description

馃悰 Bug Report

When a selection in FluentListbox is made and the selected item get removed(e.g. filtered out), the selection marker gets applied to a wrong item. Additionally, that wrongly selected item cannot be really selected anymore except selecting an other item first.

馃捇 Repro or Code Sample

<FluentListbox TOption="int"
               TValue="int"
               Multiple="false"
               Items="FilteredValues"
               ValueChanged="SelectionChanged" />

<FluentButton OnClick="ApplyFilter">Apply Filter</FluentButton>


@code {
    private ImmutableList<int> AllValues = new List<int>()
    {
        1,2,3,4,5,6,7,8,9
    }.ToImmutableList();

    private IEnumerable<int> FilteredValues = null!;

    protected override void OnInitialized()
    {
        base.OnInitialized();
        Console.WriteLine("DEBUG: Init done.");
        FilteredValues = AllValues;
    }

    private void SelectionChanged(int number)
    {
        Console.WriteLine(number);
    }

    private void ApplyFilter()
    {
        FilteredValues = AllValues.Where(i => i != 4 && i != 6);
    }
}

馃 Expected Behavior & 馃拋 Possible Solution

Behaviour like in V4: If an item that is selected is filtered out, don't internally mark an other item as selected.

馃槸 Current Behavior

Selecting Number 4 -> Okay:
Image

After using the button to apply the filter, 4 and 6 are removed. The selection marker jumps to 5, however the changed selection isn't reflected by calling the EventCallback ValueChanged. Additionally the 5 isn't selectable (as the Listbox thinks, it is selected) and is only selectable, when first an other number gets selected (if in my real code there is only one item left, I get stuck with an unselectable item).
Image

馃敠 Context

I'm using the Listbox to display several items by name. Filter gets applied programmatically after using a button or a checkbox to filter out several items (e.g. depending on their property 'status'). In some cases, I only have one item left. If there was a selection previously I get stuck with an unselectable item.

馃實 Your Environment

  • OS & Device: Windows Server 2025 running Blazor Server; Windows 11 as Client
  • Browser: Brave, Firefox, Edge (but most likely all affected)
  • .NET 10 and Fluent UI Blazor library 5.0.0-rc.5-26219.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

status:needs-investigationNeeds additional investigationv5For the next major version

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions