Skip to content

Commit

Permalink
chore: set name and automation id properly for TextElement
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed May 13, 2023
1 parent 7548790 commit d3120bc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/Uno.UI/UI/Xaml/Documents/TextElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,22 @@ public bool AllowFocusOnInteraction

#endregion

public string Name { get; set; }
private string _name;

public string Name
{
get => _name;
set
{
if (_name != value)
{
_name = value;
OnNameChangedPartial(value);
}
}
}

partial void OnNameChangedPartial(string newValue);

/// <summary>
/// Retrieves the parent RichTextBox/CRichTextBlock/TextBlock.
Expand Down
19 changes: 18 additions & 1 deletion src/Uno.UI/UI/Xaml/Documents/TextElement.wasm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
namespace Windows.UI.Xaml.Documents
using Uno.UI;
using Uno.UI.Xaml;
using Windows.UI.Xaml.Automation;

namespace Windows.UI.Xaml.Documents
{
partial class TextElement
{
Expand Down Expand Up @@ -45,5 +49,18 @@ partial void OnTextDecorationsChangedPartial()
{
this.SetTextDecorations(ReadLocalValue(TextDecorationsProperty));
}

partial void OnNameChangedPartial(string newValue)
{
if (FrameworkElementHelper.IsUiAutomationMappingEnabled)
{
AutomationProperties.SetAutomationId(this, newValue);
}

if (FeatureConfiguration.UIElement.AssignDOMXamlName)
{
WindowManagerInterop.SetName(HtmlId, newValue);
}
}
}
}

0 comments on commit d3120bc

Please sign in to comment.