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

FluentSelect's SelectedOptionChanged triggered twice with different values #1965

Closed
lasbrojen opened this issue Apr 28, 2024 · 2 comments · Fixed by #1970
Closed

FluentSelect's SelectedOptionChanged triggered twice with different values #1965

lasbrojen opened this issue Apr 28, 2024 · 2 comments · Fixed by #1970
Assignees
Labels
bug A bug
Milestone

Comments

@lasbrojen
Copy link

lasbrojen commented Apr 28, 2024

🐛 Bug Report

I have based this on an example from your website to demonstrate what I believe might be a bug. If the list used in "Items" contains an option that is set to "Selected" as true, FluentSelect’s SelectedOptionChanged event is triggered twice. The first time it is called with the selected value, and subsequently with the initial value.

In my case, the value "_myValue" remains "Eight" since my list includes an option explicitly set to "Selected."

image

The component functions correctly when initialized with all options set to "Selected" as false.

image

💻 Repro or Code Sample

<FluentSelect
    TOption="Option<string>"
    SelectedOptionChanged="MyMethod" 
    Items=@stringOptions1
    OptionText="@(i => i.Text)"
    OptionValue="@(i => i.Value)"
    OptionSelected="@(i => i.Selected)"
/>

<p style="margin-top:30px">
    Selected Value: <span style="color:red;font-size:17px; font-weight: bold">@_myValue</span>
</p>

@code{
    private string _myValue = string.Empty;
    
    public void MyMethod(Option<string> obj)
    {
        _myValue = obj?.Text;
    }

    static List<Option<string>> stringOptions1 = new()
    {
        { new Option<string> { Value = "9", Text = "Nine" } },
        { 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" } }
    };
}

🤔 Expected Behavior

Should it not just be called once?

😯 Current Behavior

The first time it is called with the selected value, and subsequently with the initial value.

🔦 Context

In my system, I am loading data that requires user editing. I need to preset the value that the user had selected during their last session. When the user selectes an option I need to trigger other actions in the systems and therefore I use SelectedOptionChanged

🌍 Your Environment

To be sure I created a brand new project from the "Fluent Blazor Web App" template.
I am testing in Microsoft Edge on a Windows 11

@microsoft-github-policy-service microsoft-github-policy-service bot added the triage New issue. Needs to be looked at label Apr 28, 2024
@vnbaaij vnbaaij added bug A bug and removed triage New issue. Needs to be looked at labels Apr 29, 2024
@vnbaaij vnbaaij self-assigned this Apr 29, 2024
@vnbaaij vnbaaij added this to the v4.7.2 milestone Apr 29, 2024
@vnbaaij
Copy link
Collaborator

vnbaaij commented Apr 29, 2024

Hi,

Yes, this is indeed a bug. The good news is I found a fix for it so that will be in the next release. I'm creating a PR for it which will be linked below.

Thanks for reporting and providing a ready to use reproduction!

vnbaaij added a commit that referenced this issue Apr 29, 2024
@vnbaaij vnbaaij closed this as completed Apr 29, 2024
@lasbrojen
Copy link
Author

Thank you 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants