Skip to content

Commit

Permalink
Fix bug where NavViewItem would report wrong type for UIA (#1800)
Browse files Browse the repository at this point in the history
* Fix bug where NavViewItem would report wrong type for UIA

* Improve comment wording and formatting

* Add missing test for UIAType of NavigationItem

* Fix formatting

* Remove redundant using statement
  • Loading branch information
marcelwgn authored and msft-github-bot committed Jan 10, 2020
1 parent d876b4e commit 1f48f11
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
16 changes: 16 additions & 0 deletions dev/NavigationView/NavigationViewItemAutomationPeer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ winrt::IInspectable NavigationViewItemAutomationPeer::GetPatternCore(winrt::Patt
return result;
}


winrt::AutomationControlType NavigationViewItemAutomationPeer::GetAutomationControlTypeCore()
{
// To be compliant with MAS 4.1.2, in DisplayMode 'Top',
// a NavigationViewItem should report itsself as TabItem
if (IsOnTopNavigation())
{
return winrt::AutomationControlType::TabItem;
}
else
{
return winrt::AutomationControlType::ListItem;
}
}


int32_t NavigationViewItemAutomationPeer::GetPositionInSetCore()
{
int32_t positionInSet = 0;
Expand Down
3 changes: 2 additions & 1 deletion dev/NavigationView/NavigationViewItemAutomationPeer.h
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.

#pragma once
Expand All @@ -19,6 +19,7 @@ class NavigationViewItemAutomationPeer :
// IAutomationPeerOverrides
winrt::hstring GetNameCore();
winrt::IInspectable GetPatternCore(winrt::PatternInterface const& patternInterface);
winrt::AutomationControlType GetAutomationControlTypeCore();

// IAutomationPeerOverrides3
int32_t GetPositionInSetCore();
Expand Down
32 changes: 32 additions & 0 deletions dev/NavigationView/NavigationView_ApiTests/NavigationViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using NavigationViewItemSeparator = Microsoft.UI.Xaml.Controls.NavigationViewItemSeparator;
using NavigationViewBackButtonVisible = Microsoft.UI.Xaml.Controls.NavigationViewBackButtonVisible;
using System.Collections.ObjectModel;
using Windows.UI.Xaml.Automation.Peers;

namespace Windows.UI.Xaml.Tests.MUXControls.ApiTests
{
Expand Down Expand Up @@ -423,6 +424,37 @@ public void VerifySingleSelection()
});
}

[TestMethod]
public void VerifyNavigationItemUIAType()
{
RunOnUIThread.Execute(() =>
{
var navView = new NavigationView();
Content = navView;

var menuItem1 = new NavigationViewItem();
var menuItem2 = new NavigationViewItem();
menuItem1.Content = "Item 1";
menuItem2.Content = "Item 2";

navView.MenuItems.Add(menuItem1);
navView.MenuItems.Add(menuItem2);
navView.Width = 1008; // forces the control into Expanded mode so that the menu renders
Content.UpdateLayout();

Verify.AreEqual(
AutomationControlType.ListItem,
NavigationViewItemAutomationPeer.CreatePeerForElement(menuItem1).GetAutomationControlType());

navView.PaneDisplayMode = NavigationViewPaneDisplayMode.Top;
Content.UpdateLayout();
Verify.AreEqual(
AutomationControlType.TabItem,
NavigationViewItemAutomationPeer.CreatePeerForElement(menuItem1).GetAutomationControlType());

});
}

[TestMethod]
public void VerifySettingsItemToolTip()
{
Expand Down

0 comments on commit 1f48f11

Please sign in to comment.