From dc3ce9fb8debb2f3c24d68ceeb1f0ef6e3efca78 Mon Sep 17 00:00:00 2001 From: Pavel Holec Date: Wed, 13 Nov 2024 14:32:12 +0100 Subject: [PATCH] Improve support for form field accessibility to cover both single-accessible element with simple text and composed element with custom views --- Sources/Orbit/Components/Heading.swift | 4 +--- Sources/Orbit/Components/Select.swift | 2 +- Sources/Orbit/Components/Text.swift | 4 +--- .../Accessibility/AccessibilityLabelValueModifier.swift | 6 +++--- Sources/Orbit/Support/Forms/FieldMessage.swift | 6 ++++++ Sources/Orbit/Support/Forms/FieldWrapper.swift | 3 --- Sources/Orbit/Support/Forms/InputContent.swift | 3 --- Sources/Orbit/Support/Text/TextRepresentable.swift | 1 + 8 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Sources/Orbit/Components/Heading.swift b/Sources/Orbit/Components/Heading.swift index 971bfa7493f..8fab1b08cb3 100644 --- a/Sources/Orbit/Components/Heading.swift +++ b/Sources/Orbit/Components/Heading.swift @@ -202,9 +202,7 @@ public extension Heading { extension Heading: TextRepresentable { public func text(environment: TextRepresentableEnvironment) -> SwiftUI.Text? { - content.isEmpty - ? nil - : textContent.text(environment: environment) + textContent.text(environment: environment) } } diff --git a/Sources/Orbit/Components/Select.swift b/Sources/Orbit/Components/Select.swift index 19e7ba85a14..510d17c4e34 100644 --- a/Sources/Orbit/Components/Select.swift +++ b/Sources/Orbit/Components/Select.swift @@ -90,7 +90,7 @@ public struct Select SwiftUI.Text? { - isEmpty - ? nil - : text(environment: environment, showTextLinks: true) + text(environment: environment, showTextLinks: true) } } diff --git a/Sources/Orbit/Support/Accessibility/AccessibilityLabelValueModifier.swift b/Sources/Orbit/Support/Accessibility/AccessibilityLabelValueModifier.swift index 384ae10094f..b3bc37414d6 100644 --- a/Sources/Orbit/Support/Accessibility/AccessibilityLabelValueModifier.swift +++ b/Sources/Orbit/Support/Accessibility/AccessibilityLabelValueModifier.swift @@ -11,7 +11,7 @@ struct AccessibilityLabelValueModifier: Vi @ViewBuilder let hint: Hint func body(content: Content) -> some View { - if isLabelTextual { + if isLabelOrValueTextual { if let childBehavior { content .accessibilityElement(children: childBehavior) @@ -31,8 +31,8 @@ struct AccessibilityLabelValueModifier: Vi } } - private var isLabelTextual: Bool { - textualLabel != nil + private var isLabelOrValueTextual: Bool { + textualLabel != nil || textualValue != nil } private var textualLabel: SwiftUI.Text? { diff --git a/Sources/Orbit/Support/Forms/FieldMessage.swift b/Sources/Orbit/Support/Forms/FieldMessage.swift index 209c2d26447..5075d7689e9 100644 --- a/Sources/Orbit/Support/Forms/FieldMessage.swift +++ b/Sources/Orbit/Support/Forms/FieldMessage.swift @@ -20,6 +20,7 @@ public struct FieldMessage: View { } Text(message.description) + .accessibility(.fieldMessage) } .iconColor(nil) .textColor(message.color) @@ -35,6 +36,11 @@ public struct FieldMessage: View { } } +// MARK: - Identifiers +public extension AccessibilityID { + static let fieldMessage = Self(rawValue: "orbit.field.message") +} + // MARK: - Previews struct FieldMessagePreviews: PreviewProvider { diff --git a/Sources/Orbit/Support/Forms/FieldWrapper.swift b/Sources/Orbit/Support/Forms/FieldWrapper.swift index 34b2e3e4226..16802fa2613 100644 --- a/Sources/Orbit/Support/Forms/FieldWrapper.swift +++ b/Sources/Orbit/Support/Forms/FieldWrapper.swift @@ -14,9 +14,6 @@ public struct FieldWrapper: View { VStack(alignment: .leading, spacing: 0) { label .textFontWeight(.medium) - // Component should expose label as part of content - .accessibility(hidden: true) - .accessibility(removeTraits: .isStaticText) .padding(.bottom, .xxSmall) content diff --git a/Sources/Orbit/Support/Forms/InputContent.swift b/Sources/Orbit/Support/Forms/InputContent.swift index 601fd886c87..224b4dcf660 100644 --- a/Sources/Orbit/Support/Forms/InputContent.swift +++ b/Sources/Orbit/Support/Forms/InputContent.swift @@ -32,9 +32,6 @@ public struct InputContent SwiftUI.Text? { switch self { case let text as SwiftUI.Text: text + case let value as SelectValue: value.value.map(SwiftUI.Text.init) case let text as TextRepresentable: text.text(environment: .init(locale: locale, localizationBundle: localizationBundle)) default: nil }