diff --git a/src/Controls/src/Core/RadioButton/RadioButton.cs b/src/Controls/src/Core/RadioButton/RadioButton.cs index 53855d94e124..1b0705728014 100644 --- a/src/Controls/src/Core/RadioButton/RadioButton.cs +++ b/src/Controls/src/Core/RadioButton/RadioButton.cs @@ -752,7 +752,7 @@ private protected override Semantics UpdateSemantics() if (ControlTemplate != null) { - string contentAsString = GetSemanticDescriptionFromContent(); + string contentAsString = ContentAsString(); if (!string.IsNullOrWhiteSpace(contentAsString) && string.IsNullOrWhiteSpace(semantics?.Description)) { @@ -764,71 +764,6 @@ private protected override Semantics UpdateSemantics() return semantics; } - string GetSemanticDescriptionFromContent() - { - if (Content is string contentText) - { - return contentText; - } - - if (Content is IView contentView) - { - // Don't fall back to ContentAsString() for view-based content — it calls ToString() - // on the view and returns a type name rather than meaningful text. - TryGetSemanticDescription(contentView, out var semanticDescription); - return semanticDescription; - } - - if (Value is string valueText && !string.IsNullOrWhiteSpace(valueText)) - { - return valueText; - } - - return ContentAsString(); - } - - static bool TryGetSemanticDescription(IView view, out string semanticDescription) - { - semanticDescription = null; - - if (view is null) - { - return false; - } - - if (!string.IsNullOrWhiteSpace(view.Semantics?.Description)) - { - semanticDescription = view.Semantics.Description; - return true; - } - - if (view is IText text && !string.IsNullOrWhiteSpace(text.Text)) - { - semanticDescription = text.Text; - return true; - } - - if (view is IContentView contentView && contentView.PresentedContent is IView presentedContent && TryGetSemanticDescription(presentedContent, out semanticDescription)) - { - return true; - } - - if (view is Microsoft.Maui.ILayout layout) - { - for (int index = 0; index < layout.Count; index++) - { - var child = layout[index]; - - if (TryGetSemanticDescription(child, out semanticDescription)) - { - return true; - } - } - } - - return false; - } - class CornerRadiusToShape : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) diff --git a/src/Controls/tests/DeviceTests/Elements/RadioButton/RadioButtonTests.cs b/src/Controls/tests/DeviceTests/Elements/RadioButton/RadioButtonTests.cs index ad99f8d6e5e8..c48b77bb8c3c 100644 --- a/src/Controls/tests/DeviceTests/Elements/RadioButton/RadioButtonTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/RadioButton/RadioButtonTests.cs @@ -101,89 +101,5 @@ await InvokeOnMainThreadAsync(() => await AssertionExtensions.WaitForGC(radioButtonHandlerRef, layoutHandlerRef, layoutPlatformRef, radioButtonPlatformRef); } - - [Fact(DisplayName = "Issue 34322 - Templated RadioButton uses content label for semantics")] - public async Task Issue34322_TemplatedRadioButtonUsesContentLabelForSemantics() - { - EnsureTemplatedRadioButtonHandlersCreated(); - - var radioButton = CreateIssue34322RadioButton("Dog", isChecked: false, useSemanticDescription: false); - - await CreateHandlerAndAddToWindow(radioButton, _ => - { - Assert.Equal("Dog", (radioButton as IView).Semantics.Description); - return Task.CompletedTask; - }); - } - - [Fact(DisplayName = "Issue 34322 - Explicit SemanticDescription is not overwritten by content-derived semantics")] - public async Task Issue34322_ExplicitSemanticDescriptionNotOverwrittenByContent() - { - EnsureTemplatedRadioButtonHandlersCreated(); - - var radioButton = new RadioButton - { - ControlTemplate = RadioButton.DefaultTemplate, - Content = new VerticalStackLayout - { - Children = - { - new Label - { - Text = "Dog" - } - } - }, - IsChecked = false, - }; - SemanticProperties.SetDescription(radioButton, "Custom Description"); - - await CreateHandlerAndAddToWindow(radioButton, _ => - { - Assert.Equal("Custom Description", (radioButton as IView).Semantics.Description); - return Task.CompletedTask; - }); - } - - void EnsureTemplatedRadioButtonHandlersCreated() - { - EnsureHandlerCreated(builder => - { - builder.ConfigureMauiHandlers(handlers => - { - handlers.AddHandler(); - handlers.AddHandler(); - handlers.AddHandler(); - handlers.AddHandler(); - handlers.AddHandler(); - handlers.AddHandler(); - handlers.AddHandler(); - }); - }); - } - - static RadioButton CreateIssue34322RadioButton(string label, bool isChecked, bool useSemanticDescription) - { - var radioButton = new RadioButton - { - ControlTemplate = RadioButton.DefaultTemplate, - Content = new VerticalStackLayout - { - Children = - { - new Label - { - Text = label - } - } - }, - IsChecked = isChecked, - }; - - if (useSemanticDescription) - SemanticProperties.SetDescription(radioButton, label); - - return radioButton; - } } -} +} \ No newline at end of file diff --git a/src/Core/src/Platform/Android/SemanticExtensions.cs b/src/Core/src/Platform/Android/SemanticExtensions.cs index 222b2d91dcd3..9245bf44bc9c 100644 --- a/src/Core/src/Platform/Android/SemanticExtensions.cs +++ b/src/Core/src/Platform/Android/SemanticExtensions.cs @@ -8,8 +8,6 @@ namespace Microsoft.Maui.Platform { public static partial class SemanticExtensions { - // Cached once to avoid repeated JNI/type lookups on every accessibility traversal. - static readonly string s_radioButtonClassName = Java.Lang.Class.FromType(typeof(global::Android.Widget.RadioButton)).Name; public static void UpdateSemanticNodeInfo(this View platformView, IView virtualView, AccessibilityNodeInfoCompat? info) { if (info == null || virtualView == null) @@ -92,13 +90,6 @@ public static void UpdateSemanticNodeInfo(this View platformView, IView virtualV if (!string.IsNullOrWhiteSpace(newText)) info.Text = newText; - if (virtualView is IRadioButton radioButton) - { - info.ClassName = s_radioButtonClassName; - info.Checkable = true; - info.Checked = radioButton.IsChecked; - } - if (!string.IsNullOrWhiteSpace(virtualView.AutomationId) && platformView?.Context != null) {