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

feat: Add two-way databinding for Checked on FluentMenuItems #3390

Open
denispaluca opened this issue Feb 18, 2025 · 3 comments · May be fixed by #3414
Open

feat: Add two-way databinding for Checked on FluentMenuItems #3390

denispaluca opened this issue Feb 18, 2025 · 3 comments · May be fixed by #3414
Labels
status:in-progress Work is in progress

Comments

@denispaluca
Copy link
Contributor

🙋 Feature Request

FluentMenuItem component has no two way databinding when using @bind-Checked.

🤔 Expected Behavior

The user should be able to control the Checked state of the FluentMenuItem.

😯 Current Behavior

You can only set the Checked property in the beginning then you have not information what state the checked flag is for a certain menu item.

💁 Possible Solution

Add the CheckedChanged event callback.

🔦 Context

I want to know which items are checked or not, and how that is changing.

💻 Examples

@microsoft-github-policy-service microsoft-github-policy-service bot added the triage New issue. Needs to be looked at label Feb 18, 2025
@rpodevns
Copy link
Contributor

Hi @denispaluca - Does the syntax below look like it'll provide the binding/callback you'd need?

@vnbaaij @dvoituron - I have this working locally. Is it something that could be added for v4?

<FluentStack  Orientation="Orientation.Vertical">
    <FluentMenu Open="true" OnCheckedChanged="HandleCheckedChanged" >
        <FluentMenuItem Id="menuitem1"
                        Role="MenuItemRole.MenuItemCheckbox"
                        @bind-Checked=menuItem1>
                            MenuItem 1 is @(menuItem1 ? "Checked" : "Unchecked")
        </FluentMenuItem>
        <FluentMenuItem Id="menuitem2"
                        Role="MenuItemRole.MenuItemCheckbox"
                        @bind-Checked=menuItem2>
                            MenuItem 2 is @(menuItem2 ? "Checked" : "Unchecked")
        </FluentMenuItem>
    </FluentMenu>
    <FluentButton OnClick="ToggleItem2">Toggle Menu item 2</FluentButton>
</FluentStack>

@code {

    private bool menuItem1 = false;
    private bool menuItem2 = false;

    private void ToggleItem2()
    {
        menuItem2 = !menuItem2;
    }

    private void HandleCheckedChanged(FluentMenuItem item)
    {
        DemoLogger.WriteLine(@$"{item.Id} {(item.Checked ? "Checked" : "Unchecked")}");
    }
}

@vnbaaij
Copy link
Collaborator

vnbaaij commented Feb 19, 2025

@rpodevns Yes, we can add that. Bring on the PR!

@vnbaaij vnbaaij added status:in-progress Work is in progress and removed triage New issue. Needs to be looked at labels Feb 19, 2025
@denispaluca
Copy link
Contributor Author

@rpodevns Yup, works perfectly!

@vnbaaij vnbaaij linked a pull request Feb 20, 2025 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:in-progress Work is in progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants