From 9871324c8e876619623af505dac12059fb977f20 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 14 Jun 2024 09:05:22 -0500 Subject: [PATCH] first cut of accessibility update Signed-off-by: Matt Bruce --- VDS/Components/DatePicker/DatePicker.swift | 38 ++++++++++++++----- .../DropdownSelect/DropdownSelect.swift | 14 +++---- .../TextFields/InputField/InputField.swift | 10 +++-- 3 files changed, 43 insertions(+), 19 deletions(-) diff --git a/VDS/Components/DatePicker/DatePicker.swift b/VDS/Components/DatePicker/DatePicker.swift index 7645cce5..1bd987fd 100644 --- a/VDS/Components/DatePicker/DatePicker.swift +++ b/VDS/Components/DatePicker/DatePicker.swift @@ -100,16 +100,14 @@ 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() - - fieldStackView.isAccessibilityElement = true - fieldStackView.accessibilityLabel = "Date Picker" - fieldStackView.accessibilityHint = "Double Tap to open" + + containerView.isAccessibilityElement = true // setting color config selectedDateLabel.textColorConfiguration = primaryColorConfiguration.eraseToAnyColorable() // tap gesture - fieldStackView + containerView .publisher(for: UITapGestureRecognizer()) .sink { [weak self] _ in guard let self else { return } @@ -147,9 +145,31 @@ open class DatePicker: EntryFieldBase, DatePickerViewControllerDelegate, UIPopov open override func updateAccessibility() { super.updateAccessibility() - fieldStackView.accessibilityLabel = "Date Picker, \(accessibilityLabelText)" - fieldStackView.accessibilityHint = isReadOnly || !isEnabled ? "" : "Double tap to open." - fieldStackView.accessibilityValue = value + 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. @@ -184,7 +204,7 @@ open class DatePicker: EntryFieldBase, DatePickerViewControllerDelegate, UIPopov controller.dismiss(animated: true) { [weak self] in guard let self else { return } self.sendActions(for: .valueChanged) - UIAccessibility.post(notification: .layoutChanged, argument: self.fieldStackView) + UIAccessibility.post(notification: .layoutChanged, argument: self.containerView) } } diff --git a/VDS/Components/DropdownSelect/DropdownSelect.swift b/VDS/Components/DropdownSelect/DropdownSelect.swift index ae07d616..e825e024 100644 --- a/VDS/Components/DropdownSelect/DropdownSelect.swift +++ b/VDS/Components/DropdownSelect/DropdownSelect.swift @@ -131,7 +131,7 @@ open class DropdownSelect: EntryFieldBase { open override func setup() { super.setup() - fieldStackView.isAccessibilityElement = true + containerView.isAccessibilityElement = true inlineDisplayLabel.isAccessibilityElement = true dropdownField.width(0) @@ -278,15 +278,15 @@ open class DropdownSelect: EntryFieldBase { open override func updateAccessibility() { super.updateAccessibility() - fieldStackView.accessibilityLabel = "Dropdown Select, \(accessibilityLabelText)" - fieldStackView.accessibilityHint = isReadOnly || !isEnabled ? "" : "has popup, Double tap to open." - fieldStackView.accessibilityValue = value + 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, fieldStackView]) + elements.append(contentsOf: [titleLabel, containerView]) if showError { elements.append(statusIcon) @@ -310,7 +310,7 @@ open class DropdownSelect: EntryFieldBase { optionsPicker.isHidden = true dropdownField.resignFirstResponder() setNeedsUpdate() - UIAccessibility.post(notification: .layoutChanged, argument: fieldStackView) + UIAccessibility.post(notification: .layoutChanged, argument: containerView) } open override var canBecomeFirstResponder: Bool { @@ -337,8 +337,8 @@ extension DropdownSelect: UIPickerViewDelegate, UIPickerViewDataSource { internal func launchPicker() { if optionsPicker.isHidden { - UIAccessibility.post(notification: .layoutChanged, argument: optionsPicker) dropdownField.becomeFirstResponder() + UIAccessibility.post(notification: .layoutChanged, argument: optionsPicker) } else { dropdownField.resignFirstResponder() } diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index a160420a..54286fa9 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -181,6 +181,9 @@ 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 + textField.heightAnchor.constraint(equalToConstant: 20).isActive = true textField.delegate = self bottomContainerStackView.insertArrangedSubview(successLabel, at: 0) @@ -230,8 +233,9 @@ open class InputField: EntryFieldBase { open override func updateAccessibility() { super.updateAccessibility() - textField.accessibilityLabel = accessibilityLabelText - textField.accessibilityHint = isReadOnly || !isEnabled ? "" : "Double tap to open." + containerView.accessibilityLabel = "Input Field, \(accessibilityLabelText)" + containerView.accessibilityHint = isReadOnly || !isEnabled ? "" : "Double tap to edit." + containerView.accessibilityValue = value } open override func updateErrorLabel() { @@ -264,7 +268,7 @@ open class InputField: EntryFieldBase { open override var accessibilityElements: [Any]? { get { var elements = [Any]() - elements.append(contentsOf: [titleLabel, textField]) + elements.append(contentsOf: [titleLabel, containerView]) if showError { elements.append(statusIcon) if let errorText, !errorText.isEmpty {