From 2163abe91a3a35c15b428cc7091169caecade05e Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 24 May 2024 10:44:16 -0500 Subject: [PATCH] ensure all classes accessibility works the same Signed-off-by: Matt Bruce --- VDS/Components/DatePicker/DatePicker.swift | 12 ++++++++++ .../DropdownSelect/DropdownSelect.swift | 10 ++++++--- .../TextFields/InputField/InputField.swift | 20 ++++++++++------- .../TextFields/TextArea/TextArea.swift | 22 +++++++++++-------- 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/VDS/Components/DatePicker/DatePicker.swift b/VDS/Components/DatePicker/DatePicker.swift index af59f901..e169cccf 100644 --- a/VDS/Components/DatePicker/DatePicker.swift +++ b/VDS/Components/DatePicker/DatePicker.swift @@ -144,6 +144,18 @@ open class DatePicker: EntryFieldBase, DatePickerViewControllerDelegate, UIPopov selectedDateLabel.isEnabled = isEnabled calendarIcon.color = iconColorConfiguration.getColor(self) } + + open override func updateAccessibility() { + super.updateAccessibility() + let label = "Date Picker, \(isReadOnly ? ", read only" : "")" + if let errorText, showError { + fieldStackView.accessibilityLabel = "\(label) ,error, \(errorText)" + } else { + fieldStackView.accessibilityLabel = label + } + fieldStackView.accessibilityHint = isReadOnly || !isEnabled ? "" : "Double tap to open." + fieldStackView.accessibilityValue = value + } /// Resets to default settings. open override func reset() { diff --git a/VDS/Components/DropdownSelect/DropdownSelect.swift b/VDS/Components/DropdownSelect/DropdownSelect.swift index f596f725..54007c5a 100644 --- a/VDS/Components/DropdownSelect/DropdownSelect.swift +++ b/VDS/Components/DropdownSelect/DropdownSelect.swift @@ -132,7 +132,6 @@ open class DropdownSelect: EntryFieldBase { super.setup() fieldStackView.isAccessibilityElement = true - fieldStackView.accessibilityLabel = "Dropdown Select" inlineDisplayLabel.isAccessibilityElement = true dropdownField.width(0) @@ -278,9 +277,14 @@ open class DropdownSelect: EntryFieldBase { open override func updateAccessibility() { super.updateAccessibility() - let selectedOption = selectedOptionLabel.text ?? "" - fieldStackView.accessibilityLabel = "Dropdown Select, \(selectedOption) \(isReadOnly ? ", read only" : "")" + let label = "Dropdown Select, \(isReadOnly ? ", read only" : "")" + if let errorText, showError { + fieldStackView.accessibilityLabel = "\(label) ,error, \(errorText)" + } else { + fieldStackView.accessibilityLabel = label + } fieldStackView.accessibilityHint = isReadOnly || !isEnabled ? "" : "Double tap to open." + fieldStackView.accessibilityValue = value } open override var accessibilityElements: [Any]? { diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index 6a4614ab..70c6ecd0 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -90,7 +90,6 @@ open class InputField: EntryFieldBase { open var textField = TextField().with { $0.translatesAutoresizingMaskIntoConstraints = false $0.font = TextStyle.bodyLarge.font - $0.isAccessibilityElement = true } /// Color configuration for the textField. @@ -211,9 +210,21 @@ open class InputField: EntryFieldBase { super.updateView() textField.isEnabled = isEnabled + textField.isUserInteractionEnabled = isEnabled && !isReadOnly textField.textColor = textFieldTextColorConfiguration.getColor(self) } + open override func updateAccessibility() { + super.updateAccessibility() + let label = "\(isReadOnly ? "read only" : "")" + if let errorText, showError { + textField.accessibilityLabel = "\(label) ,error, \(errorText)" + } else { + textField.accessibilityLabel = label + } + textField.accessibilityHint = isReadOnly || !isEnabled ? "" : "Double tap to open." + } + open override func updateErrorLabel() { super.updateErrorLabel() @@ -234,19 +245,12 @@ open class InputField: EntryFieldBase { } else { successLabel.isHidden = true } - } override func updateRules() { super.updateRules() fieldType.handler().appendRules(self) } - - /// Used to update any Accessibility properties. - open override func updateAccessibility() { - super.updateAccessibility() - textField.accessibilityLabel = showError ? "error" : nil - } open override var accessibilityElements: [Any]? { get { diff --git a/VDS/Components/TextFields/TextArea/TextArea.swift b/VDS/Components/TextFields/TextArea/TextArea.swift index af49227b..f03300d1 100644 --- a/VDS/Components/TextFields/TextArea/TextArea.swift +++ b/VDS/Components/TextFields/TextArea/TextArea.swift @@ -109,7 +109,6 @@ open class TextArea: EntryFieldBase { $0.isScrollEnabled = false $0.textContainerInset = .zero $0.textContainer.lineFragmentPadding = 0 - $0.isAccessibilityElement = true } open var maxLength: Int? { @@ -194,13 +193,24 @@ open class TextArea: EntryFieldBase { statusIcon.color = iconColorConfiguration.getColor(self) containerView.layer.borderColor = isReadOnly ? readOnlyBorderColorConfiguration.getColor(self).cgColor : borderColorConfiguration.getColor(self).cgColor - textView.isEditable = isReadOnly ? false : true + textView.isEditable = !isEnabled || isReadOnly ? false : true textView.backgroundColor = backgroundColorConfiguration.getColor(self) textView.tintColor = iconColorConfiguration.getColor(self) characterCounterLabel.surface = surface highlightCharacterOverflow() } + open override func updateAccessibility() { + super.updateAccessibility() + let label = "\(isReadOnly ? "read only" : "")" + if let errorText, showError { + textView.accessibilityLabel = "\(label) ,error, \(errorText)" + } else { + textView.accessibilityLabel = label + } + textView.accessibilityHint = isReadOnly || !isEnabled ? "" : "Double tap to open." + } + override func updateRules() { super.updateRules() @@ -224,13 +234,7 @@ open class TextArea: EntryFieldBase { stackView.addArrangedSubview(characterCounterLabel) return stackView } - - /// Used to update any Accessibility properties. - open override func updateAccessibility() { - super.updateAccessibility() - textView.accessibilityLabel = showError ? "error" : nil - } - + open override var accessibilityElements: [Any]? { get { var elements = [Any]()