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

[Accessibility] Fix teaching tip name property in buttons #6897

Merged
merged 4 commits into from
Apr 1, 2022
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
21 changes: 21 additions & 0 deletions dev/TeachingTip/InteractionTests/TeachingTipTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,27 @@ void EnableLightDismiss()
}
}

[TestMethod]
public void VerifyTeachingTipButtonsNameAutomationProperty()
{
using (var setup = new TestSetupHelper(new[] { "TeachingTip Tests", "TeachingTip Test" }))
{
elements = new TeachingTipTestPageElements();

SetActionButtonContentTo("Small text");
SetCloseButtonContent(CloseButtonContentOptions.ShortText);

OpenTeachingTip();

var actionButton = FindElement.ById("ActionButton");
var closeButton = FindElement.ById("CloseButton");

Log.Comment("Verify that action and close buttons content presenter text will update the buttons name automation property");
Verify.AreEqual(actionButton.Name, "A:Short Text.");
bkudiess marked this conversation as resolved.
Show resolved Hide resolved
Verify.AreEqual(closeButton.Name, "C:Short Text.");
}
}

private void CloseOpenAndCloseWithJustKeyboardViaF6()
{
KeyboardHelper.PressKey(Key.F6);
Expand Down
29 changes: 24 additions & 5 deletions dev/TeachingTip/TeachingTip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ void TeachingTip::OnApplyTemplate()
OnIconSourceChanged();
OnHeroContentPlacementChanged();

UpdateButtonAutomationProperties(m_actionButton.get(), ActionButtonContent());
UpdateButtonAutomationProperties(m_closeButton.get(), CloseButtonContent());

EstablishShadows();

m_isTemplateApplied = true;
Expand Down Expand Up @@ -148,11 +151,6 @@ void TeachingTip::OnPropertyChanged(const winrt::DependencyPropertyChangedEventA
}
OnTargetChanged();
}
else if (property == s_ActionButtonContentProperty ||
property == s_CloseButtonContentProperty)
{
UpdateButtonsState();
}
else if (property == s_PlacementMarginProperty)
{
OnPlacementMarginChanged();
Expand Down Expand Up @@ -199,7 +197,28 @@ void TeachingTip::OnPropertyChanged(const winrt::DependencyPropertyChangedEventA
TeachingTipTestHooks::NotifySubtitleVisibilityChanged(*this);
}
}
else if (property == s_ActionButtonContentProperty)
{
UpdateButtonsState();
winrt::IInspectable value = args.NewValue();
UpdateButtonAutomationProperties(m_actionButton.get(), value);
}
else if (property == s_CloseButtonContentProperty)
{
UpdateButtonsState();
winrt::IInspectable value = args.NewValue();
UpdateButtonAutomationProperties(m_closeButton.get(), value);
}

}

void TeachingTip::UpdateButtonAutomationProperties(const winrt::Button button, const winrt::IInspectable content)
{
if (button)
{
winrt::hstring nameHString = SharedHelpers::TryGetStringRepresentationFromObject(content);
winrt::AutomationProperties::SetName(button, nameHString);
}
}

bool TeachingTip::ToggleVisibilityForEmptyContent(const wstring_view visibleStateName, const wstring_view collapsedStateName, const winrt::hstring& content)
Expand Down
1 change: 1 addition & 0 deletions dev/TeachingTip/TeachingTip.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class TeachingTip :
void EstablishShadows();
void TrySetCenterPoint(const winrt::IUIElement9& element, const winrt::float3& centerPoint);
bool ToggleVisibilityForEmptyContent(const wstring_view visibleStateName, const wstring_view collapsedStateName, const winrt::hstring& content);
void UpdateButtonAutomationProperties(const winrt::Button button, const winrt::IInspectable content);

// The tail is designed as an 8x16 pixel shape, however it is actually a 10x20 shape which is partially occluded by the tip content.
// This is done to get the border of the tip to follow the tail shape without drawing the border on the tip edge of the tail.
Expand Down
2 changes: 1 addition & 1 deletion dev/TeachingTip/TeachingTip.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@
Style="{TemplateBinding ActionButtonStyle}"
Command="{TemplateBinding ActionButtonCommand}"
CommandParameter="{TemplateBinding ActionButtonCommandParameter}">
<ContentPresenter TextWrapping="WrapWholeWords" Content="{TemplateBinding ActionButtonContent}"/>
<ContentPresenter TextWrapping="WrapWholeWords" Content="{TemplateBinding ActionButtonContent}"/>
</Button>
<Button x:Name="CloseButton"
HorizontalAlignment="Stretch"
Expand Down
6 changes: 3 additions & 3 deletions dev/TeachingTip/TestUI/TeachingTipPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@
</ComboBox>
<Button AutomationProperties.Name="SetAutomationNameButton" Click="OnSetAutomationNameButtonClicked" Grid.Row="36" Grid.Column="1">Set</Button>

<ComboBox x:Name="PageThemeComboBox" AutomationProperties.AutomationId="PageThemeComboBox" Grid.Row="37" SelectedIndex="0"
SelectionChanged="OnPageThemeComboBoxSelectionChanged"
Header="Page Theme:">
<ComboBox x:Name="PageThemeComboBox" AutomationProperties.AutomationId="PageThemeComboBox" SelectedIndex="0" Grid.Column="0"
SelectionChanged="OnPageThemeComboBoxSelectionChanged"
Header="Page Theme:">
<ComboBoxItem x:Name="Default">Default</ComboBoxItem>
<ComboBoxItem x:Name="Light">Light</ComboBoxItem>
<ComboBoxItem x:Name="Dark">Dark</ComboBoxItem>
Expand Down