Skip to content

Commit 9aee101

Browse files
authored
[Accessibility] Fix teaching tip name property in buttons (#6897)
* sets close and action buttons automation property name * Add test and address comments * Address comments * Add spaces
1 parent 97b333a commit 9aee101

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed

dev/TeachingTip/InteractionTests/TeachingTipTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,27 @@ void EnableLightDismiss()
10121012
}
10131013
}
10141014

1015+
[TestMethod]
1016+
public void VerifyTeachingTipButtonsNameAutomationProperty()
1017+
{
1018+
using (var setup = new TestSetupHelper(new[] { "TeachingTip Tests", "TeachingTip Test" }))
1019+
{
1020+
elements = new TeachingTipTestPageElements();
1021+
1022+
SetActionButtonContentTo("Small text");
1023+
SetCloseButtonContent(CloseButtonContentOptions.ShortText);
1024+
1025+
OpenTeachingTip();
1026+
1027+
var actionButton = FindElement.ById("ActionButton");
1028+
var closeButton = FindElement.ById("CloseButton");
1029+
1030+
Log.Comment("Verify that action and close buttons content presenter text will update the buttons name automation property");
1031+
Verify.AreEqual(actionButton.Name, "A:Short Text.");
1032+
Verify.AreEqual(closeButton.Name, "C:Short Text.");
1033+
}
1034+
}
1035+
10151036
private void CloseOpenAndCloseWithJustKeyboardViaF6()
10161037
{
10171038
KeyboardHelper.PressKey(Key.F6);

dev/TeachingTip/TeachingTip.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ void TeachingTip::OnApplyTemplate()
121121
OnIconSourceChanged();
122122
OnHeroContentPlacementChanged();
123123

124+
UpdateButtonAutomationProperties(m_actionButton.get(), ActionButtonContent());
125+
UpdateButtonAutomationProperties(m_closeButton.get(), CloseButtonContent());
126+
124127
EstablishShadows();
125128

126129
m_isTemplateApplied = true;
@@ -148,11 +151,6 @@ void TeachingTip::OnPropertyChanged(const winrt::DependencyPropertyChangedEventA
148151
}
149152
OnTargetChanged();
150153
}
151-
else if (property == s_ActionButtonContentProperty ||
152-
property == s_CloseButtonContentProperty)
153-
{
154-
UpdateButtonsState();
155-
}
156154
else if (property == s_PlacementMarginProperty)
157155
{
158156
OnPlacementMarginChanged();
@@ -199,7 +197,28 @@ void TeachingTip::OnPropertyChanged(const winrt::DependencyPropertyChangedEventA
199197
TeachingTipTestHooks::NotifySubtitleVisibilityChanged(*this);
200198
}
201199
}
200+
else if (property == s_ActionButtonContentProperty)
201+
{
202+
UpdateButtonsState();
203+
winrt::IInspectable value = args.NewValue();
204+
UpdateButtonAutomationProperties(m_actionButton.get(), value);
205+
}
206+
else if (property == s_CloseButtonContentProperty)
207+
{
208+
UpdateButtonsState();
209+
winrt::IInspectable value = args.NewValue();
210+
UpdateButtonAutomationProperties(m_closeButton.get(), value);
211+
}
212+
213+
}
202214

215+
void TeachingTip::UpdateButtonAutomationProperties(const winrt::Button button, const winrt::IInspectable content)
216+
{
217+
if (button)
218+
{
219+
winrt::hstring nameHString = SharedHelpers::TryGetStringRepresentationFromObject(content);
220+
winrt::AutomationProperties::SetName(button, nameHString);
221+
}
203222
}
204223

205224
bool TeachingTip::ToggleVisibilityForEmptyContent(const wstring_view visibleStateName, const wstring_view collapsedStateName, const winrt::hstring& content)

dev/TeachingTip/TeachingTip.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class TeachingTip :
162162
void EstablishShadows();
163163
void TrySetCenterPoint(const winrt::IUIElement9& element, const winrt::float3& centerPoint);
164164
bool ToggleVisibilityForEmptyContent(const wstring_view visibleStateName, const wstring_view collapsedStateName, const winrt::hstring& content);
165+
void UpdateButtonAutomationProperties(const winrt::Button button, const winrt::IInspectable content);
165166

166167
// The tail is designed as an 8x16 pixel shape, however it is actually a 10x20 shape which is partially occluded by the tip content.
167168
// 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.

dev/TeachingTip/TeachingTip.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@
393393
Style="{TemplateBinding ActionButtonStyle}"
394394
Command="{TemplateBinding ActionButtonCommand}"
395395
CommandParameter="{TemplateBinding ActionButtonCommandParameter}">
396-
<ContentPresenter TextWrapping="WrapWholeWords" Content="{TemplateBinding ActionButtonContent}"/>
396+
<ContentPresenter TextWrapping="WrapWholeWords" Content="{TemplateBinding ActionButtonContent}"/>
397397
</Button>
398398
<Button x:Name="CloseButton"
399399
HorizontalAlignment="Stretch"

dev/TeachingTip/TestUI/TeachingTipPage.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,9 @@
285285
</ComboBox>
286286
<Button AutomationProperties.Name="SetAutomationNameButton" Click="OnSetAutomationNameButtonClicked" Grid.Row="36" Grid.Column="1">Set</Button>
287287

288-
<ComboBox x:Name="PageThemeComboBox" AutomationProperties.AutomationId="PageThemeComboBox" Grid.Row="37" SelectedIndex="0"
289-
SelectionChanged="OnPageThemeComboBoxSelectionChanged"
290-
Header="Page Theme:">
288+
<ComboBox x:Name="PageThemeComboBox" AutomationProperties.AutomationId="PageThemeComboBox" SelectedIndex="0" Grid.Column="0"
289+
SelectionChanged="OnPageThemeComboBoxSelectionChanged"
290+
Header="Page Theme:">
291291
<ComboBoxItem x:Name="Default">Default</ComboBoxItem>
292292
<ComboBoxItem x:Name="Light">Light</ComboBoxItem>
293293
<ComboBoxItem x:Name="Dark">Dark</ComboBoxItem>

0 commit comments

Comments
 (0)