Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/Core/src/Platform/iOS/SemanticExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,16 @@ public static void UpdateSemantics(this UIView platformView, IView view)
platformView.AccessibilityLabel = semantics.Description;
platformView.AccessibilityHint = semantics.Hint;

// UIControl elements automatically have IsAccessibilityElement set to true
if (platformView is not UIControl && (!string.IsNullOrWhiteSpace(semantics.Hint) || !string.IsNullOrWhiteSpace(semantics.Description)))
platformView.IsAccessibilityElement = true;
if ((!string.IsNullOrWhiteSpace(semantics.Hint) || !string.IsNullOrWhiteSpace(semantics.Description)))
{
// Most UIControl elements automatically have IsAccessibilityElement set to true
if (platformView is not UIControl)
platformView.IsAccessibilityElement = true;
// UIStepper and UIPageControl inherit from UIControl but iOS marks `IsAccessibilityElement` to false
// because they are composite controls.
else if (platformView is UIStepper || platformView is UIPageControl)
platformView.IsAccessibilityElement = true;
}

if (semantics.IsHeading)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,7 @@ public async Task SettingSemanticDescriptionMakesElementAccessible()
view.Semantics.Description = "Test";
var important = await GetValueAsync(view, handler => view.IsAccessibilityElement());

// On iOS the UIStepper control is a UIControl but iOS sets IsAccessibilityElement
// to false because it's a composite control
// https://github.com/dotnet/maui/issues/11762
if (OperatingSystem.IsIOS() && view is IStepper)
Assert.False(important);
else
Assert.True(important);
Assert.True(important);
}

[Fact(DisplayName = "Setting Semantic Hint makes element accessible")]
Expand All @@ -103,13 +97,7 @@ public async Task SettingSemanticHintMakesElementAccessible()
view.Semantics.Hint = "Test";
var important = await GetValueAsync(view, handler => view.IsAccessibilityElement());

// On iOS the UIStepper control is a UIControl but iOS sets IsAccessibilityElement
// to false because it's a composite control
// https://github.com/dotnet/maui/issues/11762
if (OperatingSystem.IsIOS() && view is IStepper)
Assert.False(important);
else
Assert.True(important);
Assert.True(important);
}

[Fact(DisplayName = "Semantic Description is set correctly"
Expand Down