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

TabView accessibility and tab size fixes #1538

Merged
merged 4 commits into from
Nov 6, 2019
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
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