diff --git a/VDS/Components/DatePicker/DatePicker.swift b/VDS/Components/DatePicker/DatePicker.swift index 1040a82c..fdc6e05f 100644 --- a/VDS/Components/DatePicker/DatePicker.swift +++ b/VDS/Components/DatePicker/DatePicker.swift @@ -100,8 +100,6 @@ open class DatePicker: EntryFieldBase, DatePickerViewControllerDelegate, UIPopov /// 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() - - containerView.isAccessibilityElement = true // setting color config selectedDateLabel.textColorConfiguration = primaryColorConfiguration.eraseToAnyColorable() @@ -142,36 +140,7 @@ open class DatePicker: EntryFieldBase, DatePickerViewControllerDelegate, UIPopov selectedDateLabel.isEnabled = isEnabled calendarIcon.color = iconColorConfiguration.getColor(self) } - - open override func updateAccessibility() { - super.updateAccessibility() - containerView.accessibilityLabel = "Date Picker, \(accessibilityLabelText)" - containerView.accessibilityHint = isReadOnly || !isEnabled ? "" : "Double tap to open." - containerView.accessibilityValue = value - } - - open override var accessibilityElements: [Any]? { - get { - var elements = [Any]() - elements.append(contentsOf: [titleLabel, containerView]) - - 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 } - } - + /// Resets to default settings. open override func reset() { super.reset() diff --git a/VDS/Components/DropdownSelect/DropdownSelect.swift b/VDS/Components/DropdownSelect/DropdownSelect.swift index 37ec7984..4b9026f1 100644 --- a/VDS/Components/DropdownSelect/DropdownSelect.swift +++ b/VDS/Components/DropdownSelect/DropdownSelect.swift @@ -131,7 +131,6 @@ open class DropdownSelect: EntryFieldBase { open override func setup() { super.setup() - containerView.isAccessibilityElement = true inlineDisplayLabel.isAccessibilityElement = true dropdownField.width(0) @@ -276,36 +275,6 @@ open class DropdownSelect: EntryFieldBase { statusIcon.color = iconColorConfiguration.getColor(self) } - open override func updateAccessibility() { - super.updateAccessibility() - containerView.accessibilityLabel = "Dropdown Select, \(accessibilityLabelText)" - containerView.accessibilityHint = isReadOnly || !isEnabled ? "" : "has popup, Double tap to open." - containerView.accessibilityValue = value - } - - open override var accessibilityElements: [Any]? { - get { - var elements = [Any]() - elements.append(contentsOf: [titleLabel, containerView]) - - 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 } - } - - @objc open func pickerDoneClicked() { optionsPicker.isHidden = true dropdownField.resignFirstResponder() diff --git a/VDS/Components/TextFields/EntryFieldBase.swift b/VDS/Components/TextFields/EntryFieldBase.swift index 2111a7f0..493aff0f 100644 --- a/VDS/Components/TextFields/EntryFieldBase.swift +++ b/VDS/Components/TextFields/EntryFieldBase.swift @@ -95,6 +95,7 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { internal var containerView: UIView = { return UIView().with { $0.translatesAutoresizingMaskIntoConstraints = false + $0.isAccessibilityElement = true } }() @@ -243,7 +244,8 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { open var accessibilityLabelText: String { var accessibilityLabels = [String]() - if let text = titleLabel.text { + + if let text = titleLabel.text?.trimmingCharacters(in: .whitespaces) { accessibilityLabels.append(text) } if isReadOnly { @@ -255,9 +257,14 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { if let errorText, showError { accessibilityLabels.append("error, \(errorText)") } + + accessibilityLabels.append("\(Self.self)") + return accessibilityLabels.joined(separator: ", ") } + open var accessibilityHintText: String = "Double tap to open" + //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- @@ -447,6 +454,35 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { } } + open override func updateAccessibility() { + super.updateAccessibility() + containerView.accessibilityLabel = accessibilityLabelText + containerView.accessibilityHint = isReadOnly || !isEnabled ? "" : accessibilityHintText + containerView.accessibilityValue = value + } + + open override var accessibilityElements: [Any]? { + get { + var elements = [Any]() + elements.append(contentsOf: [titleLabel, containerView]) + + 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 } + } + //-------------------------------------------------- // MARK: - Private Methods //-------------------------------------------------- diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index 9635cb5f..e3336b76 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -102,6 +102,7 @@ open class InputField: EntryFieldBase { open var textField = TextField().with { $0.translatesAutoresizingMaskIntoConstraints = false $0.textStyle = TextStyle.bodyLarge + $0.isAccessibilityElement = false } /// Color configuration for the textField. @@ -181,8 +182,7 @@ 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() - containerView.isAccessibilityElement = true - textField.isAccessibilityElement = false + accessibilityHintText = "Double tap to edit" textField.heightAnchor.constraint(equalToConstant: 20).isActive = true textField.delegate = self @@ -230,14 +230,7 @@ open class InputField: EntryFieldBase { textField.isEnabled = isEnabled textField.isUserInteractionEnabled = isEnabled && !isReadOnly } - - open override func updateAccessibility() { - super.updateAccessibility() - containerView.accessibilityLabel = "Input Field, \(accessibilityLabelText)" - containerView.accessibilityHint = isReadOnly || !isEnabled ? "" : "Double tap to edit." - containerView.accessibilityValue = value - } - + open override func updateErrorLabel() { super.updateErrorLabel() diff --git a/VDS/Components/TextFields/TextArea/TextArea.swift b/VDS/Components/TextFields/TextArea/TextArea.swift index 79e7b825..12fbc228 100644 --- a/VDS/Components/TextFields/TextArea/TextArea.swift +++ b/VDS/Components/TextFields/TextArea/TextArea.swift @@ -42,14 +42,14 @@ open class TextArea: EntryFieldBase { $0.spacing = VDSLayout.space3X } }() - + open var characterCounterLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) $0.textStyle = .bodySmall $0.textAlignment = .right $0.numberOfLines = 1 } - + open var minHeight: Height = .twoX { didSet { setNeedsUpdate() } } //-------------------------------------------------- @@ -101,13 +101,15 @@ open class TextArea: EntryFieldBase { open override var value: String? { return textView.text } - + /// UITextView shown in the TextArea. open var textView = TextView().with { $0.translatesAutoresizingMaskIntoConstraints = false $0.sizeToFit() - $0.isScrollEnabled = false + $0.isAccessibilityElement = false + $0.isScrollEnabled = true $0.textContainerInset = .zero + $0.autocorrectionType = .no $0.textContainer.lineFragmentPadding = 0 } @@ -137,10 +139,8 @@ 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() - containerView.isAccessibilityElement = true - textView.isAccessibilityElement = false - textView.isScrollEnabled = true - textView.autocorrectionType = .no + + accessibilityHintText = "Double tap to edit" //events textView @@ -192,14 +192,7 @@ open class TextArea: EntryFieldBase { characterCounterLabel.surface = surface highlightCharacterOverflow() } - - open override func updateAccessibility() { - super.updateAccessibility() - containerView.accessibilityLabel = "\(Self.self), \(accessibilityLabelText)" - containerView.accessibilityHint = isReadOnly || !isEnabled ? "" : "Double tap to open." - containerView.accessibilityValue = value - } - + override func updateRules() { super.updateRules() @@ -223,30 +216,7 @@ open class TextArea: EntryFieldBase { stackView.addArrangedSubview(characterCounterLabel) return stackView } - - open override var accessibilityElements: [Any]? { - get { - var elements = [Any]() - elements.append(contentsOf: [titleLabel, containerView]) - - 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 { return textView.canBecomeFirstResponder }