diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift index 1ac28ded..43750513 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift @@ -125,9 +125,9 @@ import UIKit /// Adjust accessibility label based on state of RadioButton. func updateAccessibilityLabel() { - - if let state = MVMCoreUIUtility.hardcodedString(withKey: isSelected ? "radio_selected_state" : "radio_not_selected_state") { - accessibilityLabel = state + if let message = MVMCoreUIUtility.hardcodedString(withKey: "radio_button"), + let selectedState = MVMCoreUIUtility.hardcodedString(withKey: isSelected ? "radio_selected_state" : "radio_not_selected_state") { + accessibilityLabel = message + selectedState } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAllTextAndLinks.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAllTextAndLinks.swift index bdaba9c2..fd71bd6d 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAllTextAndLinks.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAllTextAndLinks.swift @@ -22,8 +22,8 @@ import Foundation //----------------------------------------------------- public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { stack = Stack.createStack(with: [(view: radioButton, model: StackItemModel(horizontalAlignment: .fill)), - (view: eyebrowHeadlineBodyLink, model: StackItemModel(horizontalAlignment: .leading))], - axis: .horizontal) + (view: eyebrowHeadlineBodyLink, model: StackItemModel(horizontalAlignment: .leading))], + axis: .horizontal) super.init(style: style, reuseIdentifier: reuseIdentifier) } @@ -38,13 +38,11 @@ import Foundation super.setupView() addMolecule(stack) stack.restack() - radioButton.isAccessibilityElement = false - isAccessibilityElement = true - updateAccessibilityLabel() - accessibilityTraits = .button - accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "radio_action_hint") - updateAccessibilityLabel() + accessibilityTraits = radioButton.accessibilityTraits + accessibilityHint = radioButton.accessibilityHint + + // Update accessibility label on radio button state change. observation = observe(\.radioButton.isSelected, options: [.new]) { [weak self] _, _ in self?.updateAccessibilityLabel() } @@ -70,8 +68,7 @@ import Foundation } func updateAccessibilityLabel() { - - var message = MVMCoreUIUtility.hardcodedString(withKey: "radio_button") ?? "" + var message = "" radioButton.updateAccessibilityLabel() if let radioButtonLabel = radioButton.accessibilityLabel { message += radioButtonLabel + ", " @@ -85,6 +82,27 @@ import Foundation if let bodyLabel = eyebrowHeadlineBodyLink.body.text { message += bodyLabel } - accessibilityLabel = message + + let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0 + isAccessibilityElement = !linkShowing + radioButton.isAccessibilityElement = linkShowing + eyebrowHeadlineBodyLink.link.isAccessibilityElement = linkShowing + + if !linkShowing { + // Make whole cell focusable if no link. + accessibilityLabel = message + } else { + // Allow only radio button and link to be focused on. + radioButton.accessibilityLabel = message + + var elements: [UIView] = [] + if message.count > 0 { + elements.append(radioButton) + } + if eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0 { + elements.append(eyebrowHeadlineBodyLink.link) + } + accessibilityElements = elements + } } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAndPaymentMethod.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAndPaymentMethod.swift index 688f457c..7ee0b619 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAndPaymentMethod.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAndPaymentMethod.swift @@ -48,13 +48,11 @@ import UIKit stack.restack() eyebrowHeadlineBodyLink.body.textColor = .mvmOrangeAA eyebrowHeadlineBodyLink.headline.styleBoldBodySmall(true) - radioButton.isAccessibilityElement = false - isAccessibilityElement = true - updateAccessibilityLabel() - accessibilityTraits = .button - accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "radio_action_hint") - updateAccessibilityLabel() + + accessibilityTraits = radioButton.accessibilityTraits + accessibilityHint = radioButton.accessibilityHint + // Update accessibility label on radio button state change. observation = observe(\.radioButton.isSelected, options: [.new]) { [weak self] _, _ in self?.updateAccessibilityLabel() } @@ -88,30 +86,44 @@ import UIKit } func updateAccessibilityLabel() { - - var message = MVMCoreUIUtility.hardcodedString(withKey: "radio_button") ?? "" - + var message = "" radioButton.updateAccessibilityLabel() if let radioButtonLabel = radioButton.accessibilityLabel { message += radioButtonLabel + ", " } - if let leftImageLabel = leftImage.accessibilityLabel { message += leftImageLabel + ", " } - if let eyebrowLabel = eyebrowHeadlineBodyLink.eyebrow.text { message += eyebrowLabel + ", " } - if let headlineLabel = eyebrowHeadlineBodyLink.headline.text { message += headlineLabel + ", " } - if let bodyLabel = eyebrowHeadlineBodyLink.body.text { message += bodyLabel } - accessibilityLabel = message + let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0 + isAccessibilityElement = !linkShowing + radioButton.isAccessibilityElement = linkShowing + eyebrowHeadlineBodyLink.link.isAccessibilityElement = linkShowing + + if !linkShowing { + // Make whole cell focusable if no link. + accessibilityLabel = message + } else { + // Allow only radio button and link to be focused on. + radioButton.accessibilityLabel = message + + var elements: [UIView] = [] + if message.count > 0 { + elements.append(radioButton) + } + if eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0 { + elements.append(eyebrowHeadlineBodyLink.link) + } + accessibilityElements = elements + } } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonBodyText.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonBodyText.swift index d89604f9..189c08d0 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonBodyText.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonBodyText.swift @@ -44,12 +44,15 @@ open class ListLeftVariableRadioButtonBodyText: TableViewCell { addMolecule(stack) stack.restack() + + // Make the whole cell focusable. isAccessibilityElement = true radioButton.isAccessibilityElement = false - accessibilityTraits = .button - accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "radio_action_hint") + accessibilityTraits = radioButton.accessibilityTraits + accessibilityHint = radioButton.accessibilityHint updateAccessibilityLabel() + // Update accessibility label on radio button state change. observation = observe(\.radioButton.isSelected, options: [.new]) { [weak self] _, _ in self?.updateAccessibilityLabel() } @@ -79,7 +82,7 @@ open class ListLeftVariableRadioButtonBodyText: TableViewCell { func updateAccessibilityLabel() { - var message = MVMCoreUIUtility.hardcodedString(withKey: "radio_button") ?? "" + var message = "" radioButton.updateAccessibilityLabel() if let radioButtonLabel = radioButton.accessibilityLabel {