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

NavView: Navigation does not work when using Narrator in Scan Mode #7274

Merged
merged 2 commits into from
Jun 28, 2022
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
8 changes: 8 additions & 0 deletions dev/NavigationView/NavigationViewItemAutomationPeer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ winrt::hstring NavigationViewItemAutomationPeer::GetNameCore()

winrt::IInspectable NavigationViewItemAutomationPeer::GetPatternCore(winrt::PatternInterface const& pattern)
{
// Note: We are intentionally not supporting Invoke Pattern, since supporting both SelectionItem and Invoke was
// causing problems.
// See this Issue for more details: https://github.com/microsoft/microsoft-ui-xaml/issues/2702
if (pattern == winrt::PatternInterface::SelectionItem ||
// Only provide expand collapse pattern if we have children!
(pattern == winrt::PatternInterface::ExpandCollapse && HasChildren()))
Expand Down Expand Up @@ -365,6 +368,11 @@ void NavigationViewItemAutomationPeer::RemoveFromSelection()

void NavigationViewItemAutomationPeer::ChangeSelection(bool isSelected)
{
// If the item is being selected, we trigger an invoke as if the user had clicked on the item:
if(isSelected)
{
Invoke();
}
if (auto nvi = Owner().try_as<winrt::NavigationViewItem>())
{
nvi.IsSelected(isSelected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,28 @@ public void VerifySelectedItemInInvokedItem()
Verify.AreEqual("ItemWasInvokedSecomdTimeWithCorrectSelection", result.GetText());
}
}

[TestMethod]
public void VerifySelectionItemPatternDoesInvoke()
{
// When using UIA SelectionItem pattern to select a navview item, this should also trigger an
// invoke on the item.
using (var setup = new TestSetupHelper(new[] { "NavigationView Tests", "NavigationView Test" }))
{
var musicItem = FindElement.ByName("Music");
var lvi = new ListViewItem(musicItem);

lvi.Select();
Wait.ForIdle();

Log.Comment("Verify item was invoked");
var result = new TextBlock(FindElement.ByName("InvokedItemState"));
Verify.AreEqual("ItemWasSelectedInItemInvoked", result.GetText());

Log.Comment("Verify item got selected");
Verify.IsTrue(Convert.ToBoolean(musicItem.GetProperty(UIProperty.Get("SelectionItem.IsSelected"))));
}
}

[TestMethod]
public void VerifyNavigationViewItemIsSelectedWorks()
Expand Down