Skip to content

fix: "duplicate" items in FluentAutoComplete #3881

@MarvinKlein1508

Description

@MarvinKlein1508

🐛 Bug Report

FluentAutoComplete adds "the same" item twice when selected. Although the dropdown menu shows that the item has already been added. This happens when you create a new instance of the search results with the same data.

In my real app this is happening because I fetch new rows from the database everytime with Dapper.

💻 Repro or Code Sample

For IssueTester:

<FluentAutocomplete TOption="MyUser"
                    Label="Users"
                    Class="w-100"
                    Placeholder="Name"
                    OnOptionsSearch="@OnSearchUserAsync"
                    OptionText="@(item => $"{item.Username}" )"
                    @bind-SelectedOptions="Input.Users" />

@code {
    public MyInput Input { get; set; } = new();   
    public class MyInput
    {
        public IEnumerable<MyUser> Users { get; set; } = [];
    }

    public class MyUser
    {
        public int UserId { get; set; }
        public string Username { get; set; }
    }

    private async Task OnSearchUserAsync(OptionsSearchEventArgs<MyUser> e)
    {
        var users = new List<MyUser>
        {
            new MyUser { UserId = 1, Username = "Alice Wonder" },
            new MyUser { UserId = 2, Username = "Marvin Klein" },
            new MyUser { UserId = 3, Username = "Vincent Baaji" },
        };

        e.Items = users;
    }
}

🤔 Expected Behavior

I expect the control to remove the first entry because it is already been added. Somehow the component already knows that this item is part of the component because the drop down menu shows it as already added.

😯 Current Behavior

You can add the same item unlimited times.

💁 Possible Solution

Maybe use the SelectedOption EventCallback to determine if an item is already part of the list and prevent the add then.

🌍 Your Environment

  • Browser Mozilla Firefox latest version
  • .NET and Fluent UI Blazor library Version .NET 9.0.5 and 4.11.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNew issue. Needs to be looked at

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions