Skip to content

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

Closed

Description

🙋 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

Activity

  1. added
    triage
    on Feb 18, 2025
  2. rpodevns commented on Feb 19, 2025

    @rpodevns
    Contributor

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

    Vincent Baaij (@vnbaaij) Denis Voituron (@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")}");
        }
    }
  3. vnbaaij commented on Feb 19, 2025

    @vnbaaij
    Collaborator

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

  4. added
    status:in-progress
    and removed
    triage
    on Feb 19, 2025
  5. denispaluca commented on Feb 19, 2025

    @denispaluca
    ContributorAuthor

    Roland (@rpodevns) Yup, works perfectly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:in-progress

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions