-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use placeholder in lieu of header if available (#2319)
- Loading branch information
Showing
4 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters