Skip to content

Commit a564c49

Browse files
authored
NavView: Navigation does not work when using Narrator in Scan Mode (#7274)
1 parent d08303e commit a564c49

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

dev/NavigationView/NavigationViewItemAutomationPeer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ winrt::hstring NavigationViewItemAutomationPeer::GetNameCore()
4646

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

366369
void NavigationViewItemAutomationPeer::ChangeSelection(bool isSelected)
367370
{
371+
// If the item is being selected, we trigger an invoke as if the user had clicked on the item:
372+
if(isSelected)
373+
{
374+
Invoke();
375+
}
368376
if (auto nvi = Owner().try_as<winrt::NavigationViewItem>())
369377
{
370378
nvi.IsSelected(isSelected);

dev/NavigationView/NavigationView_InteractionTests/SelectionTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,28 @@ public void VerifySelectedItemInInvokedItem()
350350
Verify.AreEqual("ItemWasInvokedSecomdTimeWithCorrectSelection", result.GetText());
351351
}
352352
}
353+
354+
[TestMethod]
355+
public void VerifySelectionItemPatternDoesInvoke()
356+
{
357+
// When using UIA SelectionItem pattern to select a navview item, this should also trigger an
358+
// invoke on the item.
359+
using (var setup = new TestSetupHelper(new[] { "NavigationView Tests", "NavigationView Test" }))
360+
{
361+
var musicItem = FindElement.ByName("Music");
362+
var lvi = new ListViewItem(musicItem);
363+
364+
lvi.Select();
365+
Wait.ForIdle();
366+
367+
Log.Comment("Verify item was invoked");
368+
var result = new TextBlock(FindElement.ByName("InvokedItemState"));
369+
Verify.AreEqual("ItemWasSelectedInItemInvoked", result.GetText());
370+
371+
Log.Comment("Verify item got selected");
372+
Verify.IsTrue(Convert.ToBoolean(musicItem.GetProperty(UIProperty.Get("SelectionItem.IsSelected"))));
373+
}
374+
}
353375

354376
[TestMethod]
355377
public void VerifyNavigationViewItemIsSelectedWorks()

0 commit comments

Comments
 (0)