Skip to content

Commit 3c1aa39

Browse files
Fix accessibility for Settings toggles and hyperlinks
This commit improves the Settings screen accessibility: - Fixed an issue where toggle switches (e.g., 'Install prerelease versions') only announced their state ('Enabled'/'Disabled') by properly binding their AutomationProperties.Name to the setting's descriptive text across CheckboxCard, CheckboxButtonCard, and SecureCheckboxCard. - Fixed an issue where hyperlinks (e.g., 'Become a translator') announced strictly as 'link' without text by properly exposing the internal text of TranslatedTextBlock user controls to UI Automation.
1 parent f894f1d commit 3c1aa39

6 files changed

Lines changed: 68 additions & 25 deletions

File tree

src/UniGetUI/Controls/SettingsWidgets/ButtonCard.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@ public string ButtonText
1616
set => _button.Content = CoreTools.Translate(value);
1717
}
1818

19+
private string _text = "";
1920
public string Text
2021
{
21-
set => Header = CoreTools.Translate(value);
22+
set
23+
{
24+
_text = CoreTools.Translate(value);
25+
Header = _text;
26+
Microsoft.UI.Xaml.Automation.AutomationProperties.SetName(this, _text);
27+
Microsoft.UI.Xaml.Automation.AutomationProperties.SetLocalizedControlType(this, "grouping");
28+
}
2229
}
2330

2431
public new event EventHandler<EventArgs>? Click;

src/UniGetUI/Controls/SettingsWidgets/CheckboxButtonCard.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ public bool Checked
4343

4444
public string CheckboxText
4545
{
46-
set => _textblock.Text = CoreTools.Translate(value);
46+
set
47+
{
48+
_textblock.Text = CoreTools.Translate(value);
49+
Microsoft.UI.Xaml.Automation.AutomationProperties.SetName(this, _textblock.Text);
50+
Microsoft.UI.Xaml.Automation.AutomationProperties.SetLocalizedControlType(this, "grouping");
51+
Microsoft.UI.Xaml.Automation.AutomationProperties.SetName(_checkbox, _textblock.Text);
52+
}
4753
}
4854

4955
public string ButtonText

src/UniGetUI/Controls/SettingsWidgets/CheckboxCard.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ public bool Checked
3939

4040
public string Text
4141
{
42-
set => _textblock.Text = CoreTools.Translate(value);
42+
set
43+
{
44+
_textblock.Text = CoreTools.Translate(value);
45+
Microsoft.UI.Xaml.Automation.AutomationProperties.SetName(this, _textblock.Text);
46+
Microsoft.UI.Xaml.Automation.AutomationProperties.SetLocalizedControlType(this, "grouping");
47+
Microsoft.UI.Xaml.Automation.AutomationProperties.SetName(_checkbox, _textblock.Text);
48+
}
4349
}
4450

4551
public string WarningText

src/UniGetUI/Controls/SettingsWidgets/SecureCheckboxCard.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ public bool Checked
5353

5454
public string Text
5555
{
56-
set => _textblock.Text = CoreTools.Translate(value);
56+
set
57+
{
58+
_textblock.Text = CoreTools.Translate(value);
59+
Microsoft.UI.Xaml.Automation.AutomationProperties.SetName(this, _textblock.Text);
60+
Microsoft.UI.Xaml.Automation.AutomationProperties.SetLocalizedControlType(this, "grouping");
61+
Microsoft.UI.Xaml.Automation.AutomationProperties.SetName(_checkbox, _textblock.Text);
62+
}
5763
}
5864

5965
public string WarningText

src/UniGetUI/Controls/TranslatedTextBlock.xaml.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ public TextWrapping WrappingMode
4343
public TranslatedTextBlock()
4444
{
4545
InitializeComponent();
46+
Loaded += (s, e) =>
47+
{
48+
if (Parent is Microsoft.UI.Xaml.Controls.Primitives.ButtonBase parentBtn && string.IsNullOrEmpty(Microsoft.UI.Xaml.Automation.AutomationProperties.GetName(parentBtn)))
49+
{
50+
Microsoft.UI.Xaml.Automation.AutomationProperties.SetName(parentBtn, _textBlock.Text);
51+
}
52+
};
4653
}
4754

4855
public void ApplyText(string? text)
@@ -51,7 +58,13 @@ public void ApplyText(string? text)
5158
{
5259
if (text is not null)
5360
__text = CoreTools.Translate(text);
54-
_textBlock?.Text = __prefix + __text + __suffix;
61+
_textBlock.Text = __prefix + __text + __suffix;
62+
Microsoft.UI.Xaml.Automation.AutomationProperties.SetName(this, _textBlock.Text);
63+
64+
if (IsLoaded && Parent is Microsoft.UI.Xaml.Controls.Primitives.ButtonBase parentBtn)
65+
{
66+
Microsoft.UI.Xaml.Automation.AutomationProperties.SetName(parentBtn, _textBlock.Text);
67+
}
5568
}
5669
catch (Exception ex)
5770
{

src/UniGetUI/Pages/SettingsPages/GeneralPages/General.xaml

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<HyperlinkButton
4242
Padding="0"
4343
NavigateUri="https://github.com/Devolutions/UniGetUI/wiki#translating-wingetui"
44+
AutomationProperties.Name="Is your language missing or incomplete? Become a translator"
4445
>
4546
<widgets:TranslatedTextBlock Text="Become a translator" />
4647
</HyperlinkButton>
@@ -112,27 +113,31 @@
112113
Text="Reset UniGetUI"
113114
/>
114115

115-
<widgets:TranslatedTextBlock
116-
Margin="4,32,4,8"
117-
FontWeight="SemiBold"
118-
Text="Related settings"
119-
/>
116+
<StackPanel AutomationProperties.Name="Related settings" AutomationProperties.LocalizedControlType="grouping">
117+
<widgets:TranslatedTextBlock
118+
Margin="4,32,4,8"
119+
FontWeight="SemiBold"
120+
Text="Related settings"
121+
/>
120122

121-
<controls:SettingsCard
122-
Click="InterfaceSettingsButton_Click"
123-
CornerRadius="8"
124-
IsClickEnabled="True"
125-
>
126-
<controls:SettingsCard.Header>
127-
<widgets:TranslatedTextBlock Text="User interface preferences" />
128-
</controls:SettingsCard.Header>
129-
<controls:SettingsCard.Description>
130-
<widgets:TranslatedTextBlock Text="Application theme, startup page, package icons, clear successful installs automatically" />
131-
</controls:SettingsCard.Description>
132-
<controls:SettingsCard.HeaderIcon>
133-
<widgets:LocalIcon Icon="Interactive" />
134-
</controls:SettingsCard.HeaderIcon>
135-
</controls:SettingsCard>
123+
<controls:SettingsCard
124+
Click="InterfaceSettingsButton_Click"
125+
CornerRadius="8"
126+
IsClickEnabled="True"
127+
AutomationProperties.Name="User interface preferences"
128+
AutomationProperties.HelpText="Application theme, startup page, package icons, clear successful installs automatically"
129+
>
130+
<controls:SettingsCard.Header>
131+
<widgets:TranslatedTextBlock Text="User interface preferences" />
132+
</controls:SettingsCard.Header>
133+
<controls:SettingsCard.Description>
134+
<widgets:TranslatedTextBlock Text="Application theme, startup page, package icons, clear successful installs automatically" />
135+
</controls:SettingsCard.Description>
136+
<controls:SettingsCard.HeaderIcon>
137+
<widgets:LocalIcon Icon="Interactive" />
138+
</controls:SettingsCard.HeaderIcon>
139+
</controls:SettingsCard>
140+
</StackPanel>
136141
</StackPanel>
137142
</ScrollViewer>
138143
</Page>

0 commit comments

Comments
 (0)