Skip to content

Commit

Permalink
use placeholder in lieu of header if available (#2319)
Browse files Browse the repository at this point in the history
  • Loading branch information
krschau authored and bbonaby committed Mar 4, 2024
1 parent e8013d7 commit e51f98c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
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
{
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 @@ -190,6 +190,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

0 comments on commit e51f98c

Please sign in to comment.