From 5d1cdcfdff62d772feb8b29c901ffe6eedd2df4c Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 3 May 2024 15:27:00 -0500 Subject: [PATCH] refactored accessibility elements Signed-off-by: Matt Bruce --- .../Attributes/TooltipLabelAttribute.swift | 2 +- .../TextFields/EntryFieldBase.swift | 2 +- .../TextFields/InputField/InputField.swift | 27 +++++++++++++---- .../TextFields/TextArea/TextArea.swift | 29 +++++++++++++++---- VDS/Components/Tooltip/TooltipModel.swift | 3 ++ 5 files changed, 50 insertions(+), 13 deletions(-) diff --git a/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift b/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift index 20666b10..6b03d103 100644 --- a/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift +++ b/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift @@ -77,7 +77,7 @@ public class TooltipLabelAttribute: ActionLabelAttributeModel, TooltipLaunchable self.subscriber = subscriber self.surface = surface self.model = model - self.accessibleText = accessibleText + self.accessibleText = accessibleText ?? model.accessibleText self.presenter = presenter //create the tooltip click event diff --git a/VDS/Components/TextFields/EntryFieldBase.swift b/VDS/Components/TextFields/EntryFieldBase.swift index 644a8de1..5c549564 100644 --- a/VDS/Components/TextFields/EntryFieldBase.swift +++ b/VDS/Components/TextFields/EntryFieldBase.swift @@ -207,7 +207,7 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { open override func setup() { super.setup() - isAccessibilityElement = true + isAccessibilityElement = false addSubview(stackView) //create the wrapping view diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index 640538fe..eb67c255 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -148,7 +148,6 @@ open class InputField: EntryFieldBase { /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. open override func setup() { super.setup() - isAccessibilityElement = false minWidthConstraint = containerView.widthAnchor.constraint(greaterThanOrEqualToConstant: 0) minWidthConstraint?.isActive = true @@ -373,11 +372,29 @@ open class InputField: EntryFieldBase { open override func updateAccessibility() { super.updateAccessibility() textField.accessibilityLabel = showError ? "error" : nil - if showError { - accessibilityElements = [titleLabel, textField, statusIcon, errorLabel, helperLabel] - } else { - accessibilityElements = [titleLabel, textField, helperLabel] + } + + open override var accessibilityElements: [Any]? { + get { + var elements = [Any]() + elements.append(contentsOf: [titleLabel, textField]) + if showError { + elements.append(statusIcon) + if let errorText, !errorText.isEmpty { + elements.append(errorLabel) + } + } else if showSuccess, let successText, !successText.isEmpty { + elements.append(successLabel) + } + + if let helperText, !helperText.isEmpty { + elements.append(helperLabel) + } + + return elements } + + set { super.accessibilityElements = newValue } } open override var canBecomeFirstResponder: Bool { true } diff --git a/VDS/Components/TextFields/TextArea/TextArea.swift b/VDS/Components/TextFields/TextArea/TextArea.swift index 7229c4a9..5ea944a3 100644 --- a/VDS/Components/TextFields/TextArea/TextArea.swift +++ b/VDS/Components/TextFields/TextArea/TextArea.swift @@ -161,7 +161,6 @@ open class TextArea: EntryFieldBase { /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. open override func setup() { super.setup() - isAccessibilityElement = false containerStackView.pinToSuperView(.uniform(VDSFormControls.spaceInset)) minWidthConstraint = containerView.widthAnchor.constraint(greaterThanOrEqualToConstant: containerSize.width) minWidthConstraint?.isActive = true @@ -264,13 +263,31 @@ open class TextArea: EntryFieldBase { open override func updateAccessibility() { super.updateAccessibility() textView.accessibilityLabel = showError ? "error" : nil - if showError { - accessibilityElements = [titleLabel, textView, statusIcon, errorLabel, helperLabel] - } else { - accessibilityElements = [titleLabel, textView, helperLabel] - } } + open override var accessibilityElements: [Any]? { + get { + var elements = [Any]() + elements.append(contentsOf: [titleLabel, textView]) + + if showError { + elements.append(statusIcon) + if let errorText, !errorText.isEmpty { + elements.append(errorLabel) + } + } + + if let helperText, !helperText.isEmpty { + elements.append(helperLabel) + } + + return elements + } + + set { super.accessibilityElements = newValue } + } + + open override var canBecomeFirstResponder: Bool { true } open override func resignFirstResponder() -> Bool { diff --git a/VDS/Components/Tooltip/TooltipModel.swift b/VDS/Components/Tooltip/TooltipModel.swift index ee690d74..461fda66 100644 --- a/VDS/Components/Tooltip/TooltipModel.swift +++ b/VDS/Components/Tooltip/TooltipModel.swift @@ -17,16 +17,19 @@ extension Tooltip { public var title: String? public var content: String? public var contentView: UIView? + public var accessibleText: String? public var contentViewAlignment: UIStackView.Alignment? public init(closeButtonText: String = "Close", title: String? = nil, content: String? = nil, contentView: UIView? = nil, + accessibleText: String? = "Tooltip", contentViewAlignment: UIStackView.Alignment = .leading) { self.closeButtonText = closeButtonText self.title = title self.content = content self.contentView = contentView + self.accessibleText = accessibleText self.contentViewAlignment = contentViewAlignment } }