Skip to content

Commit

Permalink
Improve support for form field accessibility to cover both single-acc…
Browse files Browse the repository at this point in the history
…essible element with simple text and composed element with custom views
  • Loading branch information
PavelHolec committed Nov 14, 2024
1 parent e942bc8 commit dc3ce9f
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 16 deletions.
4 changes: 1 addition & 3 deletions Sources/Orbit/Components/Heading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Orbit/Components/Select.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public struct Select<Label: View, Value: View, Prompt: View, Prefix: View, Suffi
} value: {
value
} hint: {
Text(messageDescription)
SwiftUI.Text(messageDescription)
}
.accessibility(addTraits: .isButton)
.accessibility(.select)
Expand Down
4 changes: 1 addition & 3 deletions Sources/Orbit/Components/Text.swift
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,7 @@ enum TextLocalization {
extension Text: TextRepresentable {

public func text(environment: TextRepresentableEnvironment) -> SwiftUI.Text? {
isEmpty
? nil
: text(environment: environment, showTextLinks: true)
text(environment: environment, showTextLinks: true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct AccessibilityLabelValueModifier<Label: View, Value: View, Hint: View>: Vi
@ViewBuilder let hint: Hint

func body(content: Content) -> some View {
if isLabelTextual {
if isLabelOrValueTextual {
if let childBehavior {
content
.accessibilityElement(children: childBehavior)
Expand All @@ -31,8 +31,8 @@ struct AccessibilityLabelValueModifier<Label: View, Value: View, Hint: View>: Vi
}
}

private var isLabelTextual: Bool {
textualLabel != nil
private var isLabelOrValueTextual: Bool {
textualLabel != nil || textualValue != nil
}

private var textualLabel: SwiftUI.Text? {
Expand Down
6 changes: 6 additions & 0 deletions Sources/Orbit/Support/Forms/FieldMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public struct FieldMessage: View {
}

Text(message.description)
.accessibility(.fieldMessage)
}
.iconColor(nil)
.textColor(message.color)
Expand All @@ -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 {

Expand Down
3 changes: 0 additions & 3 deletions Sources/Orbit/Support/Forms/FieldWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ public struct FieldWrapper<Label: View, Content: View, Footer: View>: 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
Expand Down
3 changes: 0 additions & 3 deletions Sources/Orbit/Support/Forms/InputContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ public struct InputContent<Content: View, Label: View, Prefix: View, Suffix: Vie
.padding(.leading, .small)
.padding(.trailing, -.xxSmall)
.textColor(labelColor)
// Component should expose label as part of content
.accessibility(hidden: true)
.accessibility(removeTraits: .isStaticText)

content
}
Expand Down
1 change: 1 addition & 0 deletions Sources/Orbit/Support/Text/TextRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ extension View {
func text(locale: Locale, localizationBundle: Bundle) -> 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
}
Expand Down

0 comments on commit dc3ce9f

Please sign in to comment.