split up accessibility

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-06-05 16:15:53 -05:00
parent a043bd33f2
commit b3f810500b
5 changed files with 94 additions and 14 deletions

View File

@ -124,6 +124,7 @@ open class SelectorBase: Control, SelectorControlable {
open override func updateAccessibility() { open override func updateAccessibility() {
super.updateAccessibility() super.updateAccessibility()
accessibilityLabel = "\(Self.self)\(showError ? ", error" : "")" accessibilityLabel = "\(Self.self)\(showError ? ", error" : "")"
accessibilityHint = !isEnabled ? "" : "Double tap to open."
} }
/// This will change the state of the Selector and execute the actionBlock if provided. /// This will change the state of the Selector and execute the actionBlock if provided.

View File

@ -147,6 +147,30 @@ open class SelectorItemBase<Selector: SelectorControlable>: Control, Errorable,
open var accessibilityValueText: String? open var accessibilityValueText: String?
open var accessibilityLabelText: String {
var accessibilityLabels = [String]()
accessibilityLabels.append("\(Selector.self)")
if let text = labelText {
accessibilityLabels.append(text)
}
if let text = childText {
accessibilityLabels.append(text)
}
if !isEnabled {
accessibilityLabels.append("dimmed")
}
if let errorText, showError {
accessibilityLabels.append("error, \(errorText)")
}
return accessibilityLabels.joined(separator: ", ")
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Overrides // MARK: - Overrides
//-------------------------------------------------- //--------------------------------------------------
@ -162,9 +186,11 @@ open class SelectorItemBase<Selector: SelectorControlable>: Control, Errorable,
open override func setup() { open override func setup() {
super.setup() super.setup()
selectorView.isAccessibilityElement = false selectorView.isAccessibilityElement = true
isAccessibilityElement = true selectorView.shouldUpdateAccessibility = false
accessibilityTraits = .button
isAccessibilityElement = false
accessibilityElements = [selectorView, label, childLabel, errorLabel]
addSubview(mainStackView) addSubview(mainStackView)
mainStackView.isUserInteractionEnabled = false mainStackView.isUserInteractionEnabled = false
@ -195,8 +221,10 @@ open class SelectorItemBase<Selector: SelectorControlable>: Control, Errorable,
/// Used to update any Accessibility properties. /// Used to update any Accessibility properties.
open override func updateAccessibility() { open override func updateAccessibility() {
super.updateAccessibility() super.updateAccessibility()
setAccessibilityLabel(for: [selectorView, label, childLabel, errorLabel]) selectorView.accessibilityLabel = accessibilityLabelText
selectorView.accessibilityHint = !isEnabled ? "" : "Double tap to activate."
accessibilityValue = accessibilityValueText accessibilityValue = accessibilityValueText
} }
/// Resets to default settings. /// Resets to default settings.

View File

@ -51,6 +51,8 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable {
/// Key of whether or not updateView() is called in setNeedsUpdate() /// Key of whether or not updateView() is called in setNeedsUpdate()
open var shouldUpdateView: Bool = true open var shouldUpdateView: Bool = true
open var shouldUpdateAccessibility: Bool = true
open var surface: Surface = .light { didSet { setNeedsUpdate() } } open var surface: Surface = .light { didSet { setNeedsUpdate() } }
/// Text that will be used in the titleLabel. /// Text that will be used in the titleLabel.

View File

@ -102,8 +102,6 @@ open class DatePicker: EntryFieldBase, DatePickerViewControllerDelegate, UIPopov
super.setup() super.setup()
fieldStackView.isAccessibilityElement = true fieldStackView.isAccessibilityElement = true
fieldStackView.accessibilityLabel = "Date Picker"
fieldStackView.accessibilityHint = "Double Tap to open"
// setting color config // setting color config
selectedDateLabel.textColorConfiguration = primaryColorConfiguration.eraseToAnyColorable() selectedDateLabel.textColorConfiguration = primaryColorConfiguration.eraseToAnyColorable()

View File

@ -133,6 +133,30 @@ open class RadioBoxItem: Control, Changeable, FormFieldable, Groupable {
open var accessibilityValueText: String? open var accessibilityValueText: String?
open var accessibilityLabelText: String {
var accessibilityLabels = [String]()
accessibilityLabels.append("Radiobox")
if let text {
accessibilityLabels.append(text)
}
if let text = subText {
accessibilityLabels.append(text)
}
if let text = subTextRight {
accessibilityLabels.append(text)
}
if !isEnabled {
accessibilityLabels.append("dimmed")
}
return accessibilityLabels.joined(separator: ", ")
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Configuration Properties // MARK: - Configuration Properties
//-------------------------------------------------- //--------------------------------------------------
@ -171,8 +195,10 @@ open class RadioBoxItem: Control, Changeable, FormFieldable, Groupable {
open override func setup() { open override func setup() {
super.setup() super.setup()
isAccessibilityElement = true isAccessibilityElement = false
accessibilityTraits = .button selectorView.isAccessibilityElement = true
selectorView.accessibilityTraits = .button
addSubview(selectorView) addSubview(selectorView)
selectorView.isUserInteractionEnabled = false selectorView.isUserInteractionEnabled = false
@ -242,12 +268,8 @@ open class RadioBoxItem: Control, Changeable, FormFieldable, Groupable {
/// Used to update any Accessibility properties. /// Used to update any Accessibility properties.
open override func updateAccessibility() { open override func updateAccessibility() {
super.updateAccessibility() super.updateAccessibility()
setAccessibilityLabel(for: [textLabel, subTextLabel, subTextRightLabel]) accessibilityLabel = accessibilityLabelText
if let currentAccessibilityLabel = accessibilityLabel {
accessibilityLabel = "Radiobox, \(currentAccessibilityLabel)"
} else {
accessibilityLabel = "Radiobox"
}
if let accessibilityValueText { if let accessibilityValueText {
accessibilityValue = strikethrough accessibilityValue = strikethrough
? "\(strikethroughAccessibilityText), \(accessibilityValueText)" ? "\(strikethroughAccessibilityText), \(accessibilityValueText)"
@ -259,6 +281,35 @@ open class RadioBoxItem: Control, Changeable, FormFieldable, Groupable {
} }
} }
open override var accessibilityElements: [Any]? {
get {
var items = [Any]()
items.append(selectorView)
let elements = gatherAccessibilityElements(from: selectorView)
let views = elements.compactMap({ $0 as? UIView })
//update accessibilityLabel
selectorView.setAccessibilityLabel(for: views)
//disabled
if !isEnabled {
if let label = selectorView.accessibilityLabel, !label.isEmpty {
selectorView.accessibilityLabel = "\(label), dimmed"
} else {
selectorView.accessibilityLabel = "dimmed"
}
}
//append all children that are accessible
items.append(contentsOf: elements)
return items
}
set {}
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Private Methods // MARK: - Private Methods
//-------------------------------------------------- //--------------------------------------------------