Skip to content

Commit

Permalink
Fix issue with NavigationViewItem announcing collapsed when not havin…
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinnara committed Jul 3, 2020
1 parent 58198de commit a837a1b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ModernWpf.Controls/NavigationView/NavigationViewItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ void UpdateVisualStateForChevron()
}
}

bool HasChildren()
internal bool HasChildren()
{
return MenuItems.Count > 0 || MenuItemsSource != null || HasUnrealizedChildren;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public override object GetPattern(PatternInterface pattern)
{
if (pattern == PatternInterface.SelectionItem ||
pattern == PatternInterface.Invoke ||
pattern == PatternInterface.ExpandCollapse)
// Only provide expand collapse pattern if we have children!
(pattern == PatternInterface.ExpandCollapse && HasChildren()))
{
return this;
}
Expand Down Expand Up @@ -443,6 +444,15 @@ void ChangeSelection(bool isSelected)
}
}

bool HasChildren()
{
if (Owner is NavigationViewItem navigationViewItem)
{
return navigationViewItem.HasChildren();
}
return false;
}

enum AutomationOutput
{
Position,
Expand Down
31 changes: 31 additions & 0 deletions test/ModernWpfTestApp/ApiTests/NavigationViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,37 @@ public void VerifyNavigationItemUIAType()
});
}

[TestMethod]
public void VerifyAutomationPeerExpandCollapsePatternBehavior()
{
RunOnUIThread.Execute(() =>
{
var menuItem1 = new NavigationViewItem();
var menuItem2 = new NavigationViewItem();
var menuItem3 = new NavigationViewItem();
var menuItem4 = new NavigationViewItem();
menuItem1.Content = "Item 1";
menuItem2.Content = "Item 2";
menuItem3.Content = "Item 3";
menuItem4.Content = "Item 4";
menuItem2.MenuItems.Add(menuItem3);
menuItem4.HasUnrealizedChildren = true;
var expandPeer = NavigationViewItemAutomationPeer.CreatePeerForElement(menuItem1).GetPattern(PatternInterface.ExpandCollapse);
Verify.IsNull(expandPeer,"Verify NavigationViewItem with no children has no ExpandCollapse pattern");
expandPeer = NavigationViewItemAutomationPeer.CreatePeerForElement(menuItem2).GetPattern(PatternInterface.ExpandCollapse);
Verify.IsNotNull(expandPeer,"Verify NavigationViewItem with children has an ExpandCollapse pattern provided");
expandPeer = NavigationViewItemAutomationPeer.CreatePeerForElement(menuItem4).GetPattern(PatternInterface.ExpandCollapse);
Verify.IsNotNull(expandPeer,"Verify NavigationViewItem without children but with UnrealizedChildren set to true has an ExpandCollapse pattern provided");
});
}


[TestMethod]
public void VerifySettingsItemToolTip()
{
Expand Down

0 comments on commit a837a1b

Please sign in to comment.