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

MenuItem disabled state #1697

Merged
merged 5 commits into from
Jan 19, 2018

Conversation

r2d2rigo
Copy link
Contributor

Issue: #1696

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[X] Feature
[ ] Code style update (formatting)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build or CI related changes
[ ] Documentation content changes
[ ] Sample app changes
[ ] Other... Please describe:

What is the current behavior?

When setting IsEnabled to false on a MenuItem, the underlying Button uses default values for styling.

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • Docs have been added / updated (for bug fixes / features)
  • Sample in sample app has been added / updated (for bug fixes / features)
  • Tests for the changes have been added (for bug fixes / features) (if applicable)

What is the new behavior?

MenuItem has a new Disabled state that can be styled.

Does this PR introduce a breaking change?

[ ] Yes
[X] No

Other information

@IbraheemOsama IbraheemOsama added bug 🐛 An unexpected issue that highlights incorrect behavior controls 🎛️ labels Dec 13, 2017
@IbraheemOsama IbraheemOsama self-requested a review December 13, 2017 23:22
Copy link
Member

@IbraheemOsama IbraheemOsama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor comment and apologies for late review.

@@ -81,6 +81,13 @@ public MenuItem()
{
DefaultStyleKey = typeof(MenuItem);
IsFocusEngagementEnabled = true;

IsEnabledChanged += (s, e) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The registration for the event should be in method OnApplyTemplate and also we should unregister from the event as well :) for example you can do

`

///
protected override void OnApplyTemplate()
{
FlyoutButton = GetTemplateChild(FlyoutButtonName) as Button;
_parentMenu = this.FindParent

();
IsOpened = false;

        Items.VectorChanged -= Items_VectorChanged;
        IsEnabledChanged -= MenuItem_IsEnabledChanged;

        if (MenuFlyout == null)
        {
            MenuFlyout = new MenuFlyout();
        }
        else
        {
            MenuFlyout.Opened -= MenuFlyout_Opened;

            MenuFlyout.Closed -= MenuFlyout_Closed;
        }

        if (FlyoutButton != null)
        {
            FlyoutButton.PointerExited -= FlyoutButton_PointerExited;
            Items.VectorChanged += Items_VectorChanged;

            MenuFlyout.Opened += MenuFlyout_Opened;
            MenuFlyout.Closed += MenuFlyout_Closed;
            FlyoutButton.PointerExited += FlyoutButton_PointerExited;

            MenuFlyout.MenuFlyoutPresenterStyle = _parentMenu.MenuFlyoutStyle;
            ReAddItemsToFlyout();

            IsEnabledChanged += MenuItem_IsEnabledChanged;

            if (_isAccessKeySupported)
            {
                FlyoutButton.AccessKey = AccessKey;
                AccessKey = string.Empty;
            }
        }

        UpdateEnabledVisualState();

        base.OnApplyTemplate();
    }

    private void MenuItem_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
    {
        var menuItemControl = (MenuItem)sender;
        menuItemControl.UpdateEnabledVisualState();
    }`

@@ -13,6 +13,77 @@
<commands:NewFileCommand x:Key="NewFile" />
<commands:GenericCommand x:Key="GenericCommand" />
<converters:StringFormatConverter x:Key="StringFormatConverter" />

<Style TargetType="controls:MenuItem" x:Key="CustomDisabledStateMenuItemStyle">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this style really needed to demonstrate the functionality of the Menu?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This style has a minor difference compared to the default Disabled state - mainly the Background color. Default style keeps backwards compatibility by displaying the disabled item with the Buttons disabled background color and the one on the sample sets a transparent background.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess my question is more towards, should we have this style in the sample page? It seems to take up about half the sample, and it doesn't really show the functionality of the Menu, but how to apply a style.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @r2d2rigo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't know this question was for me! What kind of change are we looking at - removing it or improving it (more distinct disabled state)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, it was my fault, I should have been more clear. The style does not seem to related to the functionality of the control and I feel it is not necessary to showcase what the control can do. If that is not the case, please feel free to let me know. Otherwise, we should remove the style and keep the sample simple

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so here's what I think:

  • The default Disabled style for MenuItem mimics how it worked before (show the underliying Button as disabled) as to not introduce any UI changes. The style in the sample page is added to show that you can customize the Disabled state as you like, and it will work as expected.
  • But on a second thought, I think that if someone wanted to style the Disabled state they wouldn't need any guidance through this sample, due to already having knowledge on how control templating works and expecting it to just work (that's how I found this bug!).

In the end, I think we can safely remove the change to the sample app and let users know that styling the Disabled state works by themselves.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree 💯 , I'm good with merging this after the style has been removed :)

@nmetulev nmetulev merged commit 7387986 into CommunityToolkit:master Jan 19, 2018
@windowstoolkitbot
Copy link

This PR is linked to unclosed issues. Please check if one of these issues should be closed: #1696

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior controls 🎛️
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants