Skip to content

fix: always first item selected in FluentAutocomplete, when using *Templates #4128

@Prodigio

Description

@Prodigio

🐛 Bug Report

I'm using FluentAutocomplete with OptionTemplate and SelectedOptionTemplate both wrapping a FluentPersona. When clicking on an item from the popup, it always selects the first one, even if I scroll way down. When removing the templates, I can select the correct item.

💻 Repro or Code Sample

<FluentAutocomplete Id="add-employee"
                    TOption="EmployeeDto"
                    AutoComplete="on"
                    Placeholder="-- Kennung auswählen --"
                    MaximumOptionsSearch="@_availableEmployees.Count()"
                    Multiple="false"
                    SelectValueOnTab="true"
                    ShowOverlayOnEmptyResults="false"
                    Virtualize="true"
                    @bind-SelectedOption="@_selectedEmployee"
                    OnOptionsSearch="@OnSearchTermChanged">
                    @* OptionText="@(item => $"{item.Nik}: {item.FullName}")"> *@
    <OptionTemplate Context="ctx">
        <FluentPersona ImageSize="25px"
                       Initials="@($"{ctx.Name?[..1]}{ctx.Lastname?[..1]}")"
                       Name="@($"{ctx.Nik}: {ctx.FullName}")" />
    </OptionTemplate>
    <SelectedOptionTemplate Context="ctx">
        <FluentPersona ImageSize="25px"
                       Initials="@($"{ctx.Name?[..1]}{ctx.Lastname?[..1]}")"
                       Name="@($"{ctx.Nik}: {ctx.FullName}")" />
    </SelectedOptionTemplate>
</FluentAutocomplete>

🤔 Expected Behavior

I excpet that the item I click on is selected.

😯 Current Behavior

When clicking on an item from the popup, it always selects the first one, even if I scroll way down. When removing the templates, I can select the correct item.

💁 Possible Solution

None.

🔦 Context

A workaround is to use use the Multiple="true" but limit it to MaximumSelectedOptions="1" and OptionText="@(item => $"{item.Nik}: {item.FullName}").

🌍 Your Environment

  • OS & Device: Windows 11
  • Browser Microsoft Edge Version 140.0.3485.54 (Official build) (64-bit)
  • .NET 8 and Fluent UI Blazor library Version 4.12.1

Metadata

Metadata

Assignees

Labels

bugA bugcommunity:contributionIssue will/can be addressed by community contribution

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions