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

Fix issue with NavigationViewItem announcing collapsed when not having children #2770

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev/NavigationView/NavigationViewItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class NavigationViewItem :
void RotateExpandCollapseChevron(bool isExpanded);
bool IsRepeaterVisible() const;
void PropagateDepthToChildren(int depth);
bool HasChildren();

private:
winrt::UIElement const GetPresenterOrItem() const;
Expand Down Expand Up @@ -97,7 +98,6 @@ class NavigationViewItem :
bool ShouldEnableToolTip() const;
bool IsOnLeftNav() const;
bool IsOnTopPrimary() const;
bool HasChildren();

void UpdateRepeaterItemsSource();
void ReparentRepeater();
Expand Down
14 changes: 12 additions & 2 deletions dev/NavigationView/NavigationViewItemAutomationPeer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#include "pch.h"
Expand Down Expand Up @@ -48,7 +48,8 @@ winrt::IInspectable NavigationViewItemAutomationPeer::GetPatternCore(winrt::Patt
{
if (pattern == winrt::PatternInterface::SelectionItem ||
pattern == winrt::PatternInterface::Invoke ||
pattern == winrt::PatternInterface::ExpandCollapse)
// Only provide expand collapse pattern if we have children!
(pattern == winrt::PatternInterface::ExpandCollapse && HasChildren()))
{
return *this;
}
Expand Down Expand Up @@ -457,3 +458,12 @@ void NavigationViewItemAutomationPeer::ChangeSelection(bool isSelected)
nvi.IsSelected(isSelected);
}
}

bool NavigationViewItemAutomationPeer::HasChildren()
{
if (const auto& navigationViewItem = Owner().try_as<NavigationViewItem>())
{
return navigationViewItem->HasChildren();
}
return false;
}
1 change: 1 addition & 0 deletions dev/NavigationView/NavigationViewItemAutomationPeer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ class NavigationViewItemAutomationPeer :
int32_t GetPositionOrSetCountInLeftNavHelper(AutomationOutput automationOutput);
int32_t GetPositionOrSetCountInTopNavHelper(AutomationOutput automationOutput);
void ChangeSelection(bool isSelected);
bool HasChildren();
};
31 changes: 31 additions & 0 deletions dev/NavigationView/NavigationView_ApiTests/NavigationViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,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