Skip to content

Commit

Permalink
TabView accessibility and tab size fixes (#1538)
Browse files Browse the repository at this point in the history
Added name to close button, remove < and > buttons from the accessibility tree as is standard, reverted change that applied min/max sizes to tab in SizeToContent mode.
  • Loading branch information
teaP authored Nov 6, 2019
1 parent 477a848 commit cea350d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
1 change: 1 addition & 0 deletions dev/ResourceHelper/ResourceAccessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class ResourceAccessor sealed
#define SR_TeachingTipNotificationWithoutAppName L"TeachingTipNotificationWithoutAppName"
#define SR_TabViewAddButtonName L"TabViewAddButtonName"
#define SR_TabViewAddButtonTooltip L"TabViewAddButtonTooltip"
#define SR_TabViewCloseButtonName L"TabViewCloseButtonName"
#define SR_NumberBoxUpSpinButtonName L"NumberBoxUpSpinButtonName"
#define SR_NumberBoxDownSpinButtonName L"NumberBoxDownSpinButtonName"

Expand Down
11 changes: 0 additions & 11 deletions dev/TabView/InteractionTests/TabViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,6 @@ public void TabSizeAndScrollButtonsTest()
Log.Comment("Tab with larger content should be wider.");
Verify.IsGreaterThan(largerTab.BoundingRectangle.Width, smallerTab.BoundingRectangle.Width);

Log.Comment("Changing tab header to short/long.");
Button shortLongButton = FindElement.ByName<Button>("ShortLongTextButton");
shortLongButton.InvokeAndWait();
ElementCache.Refresh();

diff = Math.Abs(smallerTab.BoundingRectangle.Width - 100);
Verify.IsLessThanOrEqual(diff, 1, "Smaller text should have min width of 100");

diff = Math.Abs(largerTab.BoundingRectangle.Width - 240);
Verify.IsLessThanOrEqual(diff, 1, "Smaller text should have max width of 240");

// With largerTab now rendering wider, the scroll buttons should appear:
Verify.IsTrue(AreScrollButtonsVisible(), "Scroll buttons should appear");

Expand Down
4 changes: 4 additions & 0 deletions dev/TabView/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,8 @@
<value>Add new tab</value>
<comment>Tooltip for the add new tab button.</comment>
</data>
<data name="TabViewCloseButtonName" xml:space="preserve">
<value>Close Tab</value>
<comment>Automation name for the close button on each tab.</comment>
</data>
</root>
12 changes: 5 additions & 7 deletions dev/TabView/TabView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,6 @@ void TabView::UpdateTabWidths()
{
double tabWidth = std::numeric_limits<double>::quiet_NaN();

double minTabWidth = unbox_value<double>(SharedHelpers::FindResource(c_tabViewItemMinWidthName, winrt::Application::Current().Resources(), box_value(c_tabMinimumWidth)));
double maxTabWidth = unbox_value<double>(SharedHelpers::FindResource(c_tabViewItemMaxWidthName, winrt::Application::Current().Resources(), box_value(c_tabMaximumWidth)));

if (auto tabGrid = m_tabContainerGrid.get())
{
// Add up width taken by custom content and + button
Expand Down Expand Up @@ -572,9 +569,12 @@ void TabView::UpdateTabWidths()
}
else if (TabWidthMode() == winrt::TabViewWidthMode::Equal)
{
auto const minTabWidth = unbox_value<double>(SharedHelpers::FindResource(c_tabViewItemMinWidthName, winrt::Application::Current().Resources(), box_value(c_tabMinimumWidth)));
auto const maxTabWidth = unbox_value<double>(SharedHelpers::FindResource(c_tabViewItemMaxWidthName, winrt::Application::Current().Resources(), box_value(c_tabMaximumWidth)));

// Calculate the proportional width of each tab given the width of the ScrollViewer.
auto padding = Padding();
double tabWidthForScroller = (availableWidth - (padding.Left + padding.Right)) / (double)(TabItems().Size());
auto const padding = Padding();
auto const tabWidthForScroller = (availableWidth - (padding.Left + padding.Right)) / (double)(TabItems().Size());

tabWidth = std::clamp(tabWidthForScroller, minTabWidth, maxTabWidth);

Expand Down Expand Up @@ -614,8 +614,6 @@ void TabView::UpdateTabWidths()
if (tvi)
{
tvi.Width(tabWidth);
tvi.MaxWidth(maxTabWidth);
tvi.MinWidth(minTabWidth);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions dev/TabView/TabView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
</Grid.ColumnDefinitions>

<RepeatButton x:Name="ScrollDecreaseButton"
AutomationProperties.AccessibilityView="Raw"
VerticalAlignment="Bottom"
Width="{ThemeResource TabViewItemScrollButtonWidth}"
Height="{ThemeResource TabViewItemScrollButtonHeight}"
Expand All @@ -194,6 +195,7 @@
contract4Present:TabFocusNavigation="Once" />

<RepeatButton x:Name="ScrollIncreaseButton"
AutomationProperties.AccessibilityView="Raw"
Grid.Column="2"
VerticalAlignment="Bottom"
HorizontalAlignment="Center"
Expand Down
7 changes: 7 additions & 0 deletions dev/TabView/TabViewItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ void TabViewItem::OnApplyTemplate()
auto closeButton = GetTemplateChildT<winrt::Button>(L"CloseButton", controlProtected);
if (closeButton)
{
// Do localization for the close button automation name
if (winrt::AutomationProperties::GetName(closeButton).empty())
{
auto const closeButtonName = ResourceAccessor::GetLocalizedStringResource(SR_TabViewCloseButtonName);
winrt::AutomationProperties::SetName(closeButton, closeButtonName);
}

m_closeButtonClickRevoker = closeButton.Click(winrt::auto_revoke, { this, &TabViewItem::OnCloseButtonClick });
}
return closeButton;
Expand Down

0 comments on commit cea350d

Please sign in to comment.