Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: FluentSelect selected item disappears after OnInitializedAsync completes. #2813

Closed
Maintenance-Partnership-Systems opened this issue Oct 15, 2024 · 1 comment · Fixed by #2840
Assignees
Labels
bug A bug status:in-progress Work is in progress
Milestone

Comments

@Maintenance-Partnership-Systems
Copy link

Maintenance-Partnership-Systems commented Oct 15, 2024

🐛 Bug Report

Using FluentSelect in a Blazor WebAssembly application, if the OnInitializedAsync includes an await call, then after the await call completes the FluentSelect is set to blank instead of its correct Selected value.

Below is a simplified reproduction based on one of the FluentSelect examples. If you comment out the "await Task.Delay (1000)" it works fine.

🔦 Context

The actual use case that brought this to light was trying to initialise a FluentSelect using a set of option string values obtained from a Web API (via an awaited call in OnIntializedAsync), and then having it pre-select the user's previous last choice from a string value stored in Blazor.LocalStorage.

In that more complex example everything in the underlying data structures had the correct values, right down to the correct Options entry in the options list having its Selected attribute set, but still the dropdown initially fails to reflect the Selected value. Thereafter it works fine (chaning selected value, switching to other tabs in the app and back), but refreshing the page resets the dropdown to the first option, regardless of the underlying data values.

I haven't tested if the behaviour is different for a Blazor Server application.

💻 Repro or Code Sample

@page "/TESTPAGE"

<h4>From a List of Option&lt;string&gt; items</h4>
<p>Second item in the list is initially selected through the <code>OptionSelected</code> (Func delegate) parameter.</p>

<FluentSelect Items=@stringOptions1
               OptionText="@(i => i.Text)"
               OptionValue="@(i => i.Value)"
               OptionSelected="@(i => i.Selected)"
               @bind-Value="@stringValue" />
<p>
    Selected Value: @stringValue<br />
</p>


@code {

  string? stringValue;

  static List<Option<string>> stringOptions1 = new()
    {
        { new Option<string> { Value = "9", Text = "Nine", Icon = (new Icons.Regular.Size24.AppsList(), Color.Neutral, "start" ) } },
        { new Option<string> { Value = "8", Text = "Eight", Selected = true } },
        { new Option<string> { Value = "7", Text = "Seven" } },
        { new Option<string> { Value = "6", Text = "Six" } },
        { new Option<string> { Value = "5", Text = "Five" } },
        { new Option<string> { Value = "4", Text = "Four" } },
        { new Option<string> { Value = "3", Text = "Three" } },
        { new Option<string> { Value = "2", Text = "Two" } },
        { new Option<string> { Value = "1", Text = "One" } }

    };

  protected override async Task OnInitializedAsync ()
  {
    await base.OnInitializedAsync ();
    await Task.Delay (1000);
  }
}

🤔 Expected Behavior

The dropdown should show item "Eight" selected after > 1 second has elapsed.

😯 Current Behavior

Initially the dropdown shows item "Eight" selected. After 1 second the dropdown display goes blank.

Tested Firefox, Edge & Chrome - all have same behaviour.

🌍 Your Environment

Visual Studio 2022, Windows 11
NET 8 Blazor WebAssembly web application,
using Microsoft.FluentUi.AspNetCore.Components 4.10.2
Microsoft.AspNetCore.Components.WebAssembly 8.0.10

@microsoft-github-policy-service microsoft-github-policy-service bot added the triage New issue. Needs to be looked at label Oct 15, 2024
@vnbaaij vnbaaij added bug A bug status:needs-investigation Needs additional investigation and removed triage New issue. Needs to be looked at labels Oct 15, 2024
@vnbaaij
Copy link
Collaborator

vnbaaij commented Oct 15, 2024

It happens on Server as well. We'll look into it.

@vnbaaij vnbaaij added this to the v4.10.3 milestone Oct 18, 2024
@vnbaaij vnbaaij added status:in-progress Work is in progress and removed status:needs-investigation Needs additional investigation labels Oct 19, 2024
@vnbaaij vnbaaij self-assigned this Oct 19, 2024
vnbaaij added a commit that referenced this issue Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug status:in-progress Work is in progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants