From 64bd3c7c0884cc2a36528dfee4b48e8bf95208b7 Mon Sep 17 00:00:00 2001 From: Rachel Kang Date: Fri, 21 Oct 2022 12:33:36 -0400 Subject: [PATCH 01/10] First attempt of radiobutton a11y --- .../RadioButton/RadioButton.Impl.cs | 16 ++++++ .../RadioButton/RadioButtonHandler.iOS.cs | 6 +-- src/Core/src/Platform/iOS/MauiRadioButton.cs | 54 +++++++++++++++++++ 3 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 src/Core/src/Platform/iOS/MauiRadioButton.cs diff --git a/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Impl.cs b/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Impl.cs index 4f3f124e1eb7..b1e8df126d4a 100644 --- a/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Impl.cs +++ b/src/Controls/src/Core/HandlerImpl/RadioButton/RadioButton.Impl.cs @@ -19,5 +19,21 @@ public partial class RadioButton : IRadioButton Color IButtonStroke.StrokeColor => (Color)GetValue(BorderColorProperty); int IButtonStroke.CornerRadius => (int)GetValue(CornerRadiusProperty); + + Semantics _semantics; + + Semantics IView.Semantics + { + get + { + if (ControlTemplate != null) + { + _semantics ??= new Semantics(); + _semantics.Description = SemanticProperties.GetDescription(this) ?? this.ContentAsString(); + } + + return _semantics; + } + } } } \ No newline at end of file diff --git a/src/Core/src/Handlers/RadioButton/RadioButtonHandler.iOS.cs b/src/Core/src/Handlers/RadioButton/RadioButtonHandler.iOS.cs index e94e21deb617..9fc9f75cc583 100644 --- a/src/Core/src/Handlers/RadioButton/RadioButtonHandler.iOS.cs +++ b/src/Core/src/Handlers/RadioButton/RadioButtonHandler.iOS.cs @@ -9,11 +9,7 @@ protected override ContentView CreatePlatformView() _ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} must be set to create a {nameof(ContentView)}"); _ = MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} cannot be null"); - return new ContentView - { - CrossPlatformMeasure = VirtualView.CrossPlatformMeasure, - CrossPlatformArrange = VirtualView.CrossPlatformArrange - }; + return new MauiRadioButton(VirtualView); } public override void SetVirtualView(IView view) diff --git a/src/Core/src/Platform/iOS/MauiRadioButton.cs b/src/Core/src/Platform/iOS/MauiRadioButton.cs new file mode 100644 index 000000000000..0b5f5f32ad82 --- /dev/null +++ b/src/Core/src/Platform/iOS/MauiRadioButton.cs @@ -0,0 +1,54 @@ +using System; +using CoreGraphics; +using Microsoft.Maui.Graphics; +using ObjCRuntime; +using UIKit; + +namespace Microsoft.Maui.Platform +{ + public class MauiRadioButton : ContentView + { + IRadioButton _radioButton; + UIAccessibilityTrait _accessibilityTraits; + + public MauiRadioButton(IRadioButton virtualView) + { + _radioButton = virtualView; + CrossPlatformMeasure = virtualView.CrossPlatformMeasure; + CrossPlatformArrange = virtualView.CrossPlatformArrange; + IsAccessibilityElement = true; + } + + static UIKit.UIAccessibilityTrait? s_switchAccessibilityTraits; + UIKit.UIAccessibilityTrait SwitchAccessibilityTraits + { + get + { + // Accessibility Traits are none if VO is off + // So we return None until we detect that it's been turned on + if (base.AccessibilityTraits == UIAccessibilityTrait.None) + return UIAccessibilityTrait.None; + + if (s_switchAccessibilityTraits == null || + s_switchAccessibilityTraits == UIKit.UIAccessibilityTrait.None) + { + s_switchAccessibilityTraits = new UIKit.UISwitch().AccessibilityTraits; + } + + return s_switchAccessibilityTraits ?? UIKit.UIAccessibilityTrait.None; + } + } + + public override UIAccessibilityTrait AccessibilityTraits + { + get => _accessibilityTraits |= SwitchAccessibilityTraits; + set => _accessibilityTraits = value | SwitchAccessibilityTraits; + } + + public override string? AccessibilityValue + { + get => (_radioButton.IsChecked) ? "1" : "0"; + set { } + } + } +} \ No newline at end of file From 2f8ad7940100420fb62a61f5fd372bc0b53a8e4f Mon Sep 17 00:00:00 2001 From: Rachel Kang Date: Wed, 2 Nov 2022 15:58:40 -0400 Subject: [PATCH 02/10] Make Switch trait work as expected --- src/Core/src/Platform/iOS/MauiRadioButton.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Core/src/Platform/iOS/MauiRadioButton.cs b/src/Core/src/Platform/iOS/MauiRadioButton.cs index 0b5f5f32ad82..1694258173de 100644 --- a/src/Core/src/Platform/iOS/MauiRadioButton.cs +++ b/src/Core/src/Platform/iOS/MauiRadioButton.cs @@ -24,11 +24,6 @@ UIKit.UIAccessibilityTrait SwitchAccessibilityTraits { get { - // Accessibility Traits are none if VO is off - // So we return None until we detect that it's been turned on - if (base.AccessibilityTraits == UIAccessibilityTrait.None) - return UIAccessibilityTrait.None; - if (s_switchAccessibilityTraits == null || s_switchAccessibilityTraits == UIKit.UIAccessibilityTrait.None) { @@ -47,7 +42,7 @@ public override UIAccessibilityTrait AccessibilityTraits public override string? AccessibilityValue { - get => (_radioButton.IsChecked) ? "1" : "0"; + get => _radioButton.IsChecked ? "1" : "0"; set { } } } From 62f3ae445c475b4d119df0df4cacb8edfecaf84a Mon Sep 17 00:00:00 2001 From: Rachel Kang Date: Wed, 2 Nov 2022 15:59:06 -0400 Subject: [PATCH 03/10] Update control gallery sample --- .../RadioButtonGalleries/ContentProperties.xaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Controls/samples/Controls.Sample/Pages/Controls/RadioButtonGalleries/ContentProperties.xaml b/src/Controls/samples/Controls.Sample/Pages/Controls/RadioButtonGalleries/ContentProperties.xaml index 5df45beb7487..8eb227d28722 100644 --- a/src/Controls/samples/Controls.Sample/Pages/Controls/RadioButtonGalleries/ContentProperties.xaml +++ b/src/Controls/samples/Controls.Sample/Pages/Controls/RadioButtonGalleries/ContentProperties.xaml @@ -43,6 +43,22 @@ +