Skip to content

fix: SelectedOptionsChanged Event Invoke Twice in FluentAutocomplete #3111

@nassers

Description

@nassers

🐛 Bug Report

In FluentAutocomplete component, SelectedOptionsChanged event invokes twice.

💻 Repro or Code Sample

@page "/autocomplete"

<FluentAutocomplete TOption="Country"
                    AutoComplete="off"
                    Autofocus="true"
                    Label="Select a country"
                    Width="250px"
                    Placeholder="Select countries"
                    OnOptionsSearch="@OnSearchAsync"
                    MaximumSelectedOptions="5"
                    OptionText="@(item => item.Name)"
                    SelectedOptions="@SelectedItems"
                    SelectedOptionsChanged="OnChange" />

@code
{
    IEnumerable<Country> SelectedItems = Array.Empty<Country>();

    class Country
    {
        public string Name { get; set; }
    }

    List<Country> Data = new List<Country>
    {
        new Country { Name = "Afghanistan" },
        new Country { Name = "Argentina" },
        new Country { Name = "Armenia" },
        new Country { Name = "Australia" },
        new Country { Name = "Austria" },
        new Country { Name = "Azerbaijan" },
        new Country { Name = "Bahamas" },
        new Country { Name = "Bahrain" },
        new Country { Name = "Bangladesh" },
        new Country { Name = "Belgium" },
        new Country { Name = "Canada" },
        new Country { Name = "China" },
    };

    private async Task OnSearchAsync(OptionsSearchEventArgs<Country> e)
    {
        e.Items = Data.Where(i => i.Name.StartsWith(e.Text, StringComparison.OrdinalIgnoreCase)).OrderBy(i => i.Name);
    }

    private async Task OnChange(IEnumerable<Country> items)
    {

        foreach (var item in items)
        {
            Console.WriteLine(item.Name);
        }

        SelectedItems = items;
    }
}

🤔 Expected Behavior

After selecting for example "Afghanistan", It must print Afghanistan once in browser's console.

😯 Current Behavior

But it prints "Afghanistan" twice.

🌍 Your Environment

  • OS & Device: Windows on PC
  • Browser: Google Chrome, FireFox
  • .NET 9.0
  • Fluent UI Version 4.11.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions