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

ChoiceSets in Adaptive Cards do not have accessible Names if they don't have a Label #2319

Merged
merged 1 commit into from
Mar 1, 2024
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
44 changes: 44 additions & 0 deletions common/Renderers/AccessibleChoiceSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Linq;
using AdaptiveCards.ObjectModel.WinUI3;
using AdaptiveCards.Rendering.WinUI3;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Automation;
using Microsoft.UI.Xaml.Controls;

namespace DevHome.Common.Renderers;

public class AccessibleChoiceSet : IAdaptiveElementRenderer
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Can add a comment about this being a temp change until AdaptiveCards implements this.

public UIElement Render(IAdaptiveCardElement element, AdaptiveRenderContext context, AdaptiveRenderArgs renderArgs)
{
var renderer = new AdaptiveChoiceSetInputRenderer();

if (element is AdaptiveChoiceSetInput choiceSet)
{
// Label property corresponds to the Header dependency property on the ComboBox.
var header = choiceSet.Label;
var placeholderText = choiceSet.Placeholder;

// If there is no Header, there will not be an accessible Name.
// Use the Placeholder text as the accessible Name if possible.
if (string.IsNullOrEmpty(header) && !string.IsNullOrEmpty(placeholderText))
{
var result = renderer.Render(choiceSet, context, renderArgs);
if (result is StackPanel stackPanel)
{
var comboBox = stackPanel.Children.First() as ComboBox;
if (comboBox != null)
{
AutomationProperties.SetName(comboBox, placeholderText);
return stackPanel;
}
}
}
}

return renderer.Render(element, context, renderArgs);
}
}
1 change: 1 addition & 0 deletions settings/DevHome.Settings/Views/AccountsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ private async Task ConfigureLoginUIRenderer(AdaptiveCardRenderer renderer)

// Add custom Adaptive Card renderer for LoginUI as done for Widgets.
renderer.ElementRenderers.Set(LabelGroup.CustomTypeString, new LabelGroupRenderer());
renderer.ElementRenderers.Set("Input.ChoiceSet", new AccessibleChoiceSet());

var hostConfigContents = string.Empty;
var hostConfigFileName = (ActualTheme == ElementTheme.Light) ? "LightHostConfig.json" : "DarkHostConfig.json";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private async Task ConfigureWidgetRenderer()
{
// Add custom Adaptive Card renderer.
_renderer.ElementRenderers.Set(LabelGroup.CustomTypeString, new LabelGroupRenderer());
_renderer.ElementRenderers.Set("Input.ChoiceSet", new AccessibleChoiceSet());

// A different host config is used to render widgets (adaptive cards) in light and dark themes.
await UpdateHostConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ private async Task ConfigureLoginUIRenderer(AdaptiveCardRenderer renderer, Eleme

// Add custom Adaptive Card renderer for LoginUI as done for Widgets.
renderer.ElementRenderers.Set(LabelGroup.CustomTypeString, new LabelGroupRenderer());
renderer.ElementRenderers.Set("Input.ChoiceSet", new AccessibleChoiceSet());

var hostConfigContents = string.Empty;
var hostConfigFileName = (elementTheme == ElementTheme.Light) ? "LightHostConfig.json" : "DarkHostConfig.json";
Expand Down
Loading