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

Add TabView SelectionPattern #2856

Merged
merged 9 commits into from
Jul 20, 2020
Merged
28 changes: 28 additions & 0 deletions dev/TabView/APITests/TabViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
using Common;
using Microsoft.UI.Xaml.Controls;
using System.Collections.Generic;
using Windows.UI.Xaml.Automation.Peers;
using Windows.UI.Xaml.Automation;
using Windows.UI.Xaml.Automation.Provider;

#if USING_TAEF
using WEX.TestExecution;
Expand Down Expand Up @@ -84,6 +87,31 @@ public void VerifyCompactTabWidthVisualStates()
});
}

[TestMethod]
public void VerifyUIABehavior()
{
RunOnUIThread.Execute(() =>
{
TabView tabView = new TabView();
Content = tabView;

tabView.TabItems.Add(CreateTabViewItem("Item 0", Symbol.Add));
tabView.TabItems.Add(CreateTabViewItem("Item 1", Symbol.AddFriend));
tabView.TabItems.Add(CreateTabViewItem("Item 2"));

Content.UpdateLayout();

var tabViewPeer = FrameworkElementAutomationPeer.CreatePeerForElement(tabView);
Verify.IsNotNull(tabViewPeer);
var tabViewSelectionPattern = tabViewPeer.GetPattern(PatternInterface.Selection);
Verify.IsNotNull(tabViewSelectionPattern);
var selectionProvider = tabViewSelectionPattern as ISelectionProvider;
// Tab controls must require selection
Verify.IsTrue(selectionProvider.IsSelectionRequired);
});
}


private static void VerifyTabWidthVisualStates(IList<object> items, bool isCompact)
{
foreach (var item in items)
Expand Down
28 changes: 28 additions & 0 deletions dev/TabView/TabViewAutomationPeer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ TabViewAutomationPeer::TabViewAutomationPeer(winrt::TabView const& owner)
// IAutomationPeerOverrides
winrt::IInspectable TabViewAutomationPeer::GetPatternCore(winrt::PatternInterface const& patternInterface)
{
if (patternInterface == winrt::PatternInterface::Selection)
{
return *this;
}
return __super::GetPatternCore(patternInterface);
}

Expand All @@ -31,3 +35,27 @@ winrt::AutomationControlType TabViewAutomationPeer::GetAutomationControlTypeCore
return winrt::AutomationControlType::Tab;
}

bool TabViewAutomationPeer::CanSelectMultiple()
{
return false;
}

bool TabViewAutomationPeer::IsSelectionRequired()
{
return true;
}

winrt::com_array<winrt::Windows::UI::Xaml::Automation::Provider::IRawElementProviderSimple> TabViewAutomationPeer::GetSelection()
{
if (auto tabView = Owner().try_as<TabView>())
{
if (auto tabViewItem = tabView->ContainerFromIndex(tabView->SelectedIndex()).try_as<winrt::TabViewItem>())
{
if (auto peer = winrt::FrameworkElementAutomationPeer::CreatePeerForElement(tabViewItem))
{
return { ProviderFromPeer(peer) };
}
}
}
return {};
}
9 changes: 8 additions & 1 deletion dev/TabView/TabViewAutomationPeer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#include "TabViewAutomationPeer.g.h"

class TabViewAutomationPeer :
public ReferenceTracker<TabViewAutomationPeer, winrt::implementation::TabViewAutomationPeerT>
public ReferenceTracker<TabViewAutomationPeer,
winrt::implementation::TabViewAutomationPeerT,
winrt::ISelectionProvider>
{

public:
Expand All @@ -17,4 +19,9 @@ class TabViewAutomationPeer :
winrt::IInspectable GetPatternCore(winrt::PatternInterface const& patternInterface);
hstring GetClassNameCore();
winrt::AutomationControlType GetAutomationControlTypeCore();

// ISelectionProvider
bool CanSelectMultiple();
bool IsSelectionRequired();
winrt::com_array<winrt::Windows::UI::Xaml::Automation::Provider::IRawElementProviderSimple> GetSelection();
};