diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableCheckboxAllTextAndLinks.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableCheckboxAllTextAndLinks.swift index ff1c6e1b..9c8976f6 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableCheckboxAllTextAndLinks.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableCheckboxAllTextAndLinks.swift @@ -53,7 +53,7 @@ import Foundation checkbox.isAccessibilityElement = false accessibilityTraits = checkbox.accessibilityTraits accessibilityHint = checkbox.accessibilityHint - // Update accessibility label on radio button state change. + // Update accessibility label on checkbox state change. observation = observe(\.checkbox.isSelected, options: [.new]) { [weak self] _, _ in self?.updateAccessibilityLabel() } @@ -92,16 +92,8 @@ import Foundation message += checkboxLabel + ", " } - if let eyebrowLabel = eyebrowHeadlineBodyLink.eyebrow.text, !eyebrowLabel.isEmpty { - message += eyebrowLabel + ", " - } - - if let headlineLabel = eyebrowHeadlineBodyLink.headline.text, !headlineLabel.isEmpty { - message += headlineLabel + ", " - } - - if let bodyLabel = eyebrowHeadlineBodyLink.body.text, !bodyLabel.isEmpty { - message += bodyLabel + if let label = eyebrowHeadlineBodyLink.getAccessibilityMessage() { + message += label } let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0 @@ -114,19 +106,9 @@ import Foundation // Make whole cell focusable if no link. accessibilityLabel = message } else { - // Allow only radio button and link to be focused on. + // Allow only checkbox and link to be focused on. checkbox.accessibilityLabel = message - var elements: [UIView] = [] - - if message.count > 0 { - elements.append(checkbox) - } - - if linkShowing { - elements.append(eyebrowHeadlineBodyLink.link) - } - - accessibilityElements = elements + accessibilityElements = [checkbox, eyebrowHeadlineBodyLink.link] } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableCheckboxBodyText.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableCheckboxBodyText.swift index 326c9320..1d83cbfb 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableCheckboxBodyText.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableCheckboxBodyText.swift @@ -52,7 +52,7 @@ import Foundation checkbox.isAccessibilityElement = false accessibilityTraits = checkbox.accessibilityTraits accessibilityHint = checkbox.accessibilityHint - // Update accessibility label on radio button state change. + // Update accessibility label on checkbox state change. observation = observe(\.checkbox.isSelected, options: [.new]) { [weak self] _, _ in self?.updateAccessibilityLabel() } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconAllTextLinks.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconAllTextLinks.swift index 1f8a6a43..9e4d7533 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconAllTextLinks.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconAllTextLinks.swift @@ -42,7 +42,6 @@ import Foundation leftImage.imageView.contentMode = .scaleAspectFit addMolecule(stack) stack.restack() - updateAccessibilityLabel() } //-------------------------------------------------- @@ -63,57 +62,40 @@ import Foundation return 140 } + func getAccessibilityMessage() -> String? { + guard let leftImageLabel = leftImage.accessibilityLabel else { + return eyebrowHeadlineBodyLink.getAccessibilityMessage() + } + guard let label = eyebrowHeadlineBodyLink.getAccessibilityMessage() else { + return leftImageLabel + } + return leftImageLabel + ", " + label + } + func updateAccessibilityLabel() { - var message = "" - - 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 - } - let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0 isAccessibilityElement = !linkShowing + accessibilityTraits = (isAccessibilityElement && accessoryView != nil) ? .button : .none eyebrowHeadlineBodyLink.link.isAccessibilityElement = linkShowing if !linkShowing { // Make whole cell focusable if no link. - accessibilityLabel = message + accessibilityLabel = getAccessibilityMessage() + accessibilityElements = nil + } else if let accessoryView = accessoryView { + // Both caret and link. Read all content on caret. + accessoryView.accessibilityLabel = getAccessibilityMessage() + accessibilityElements = [accessoryView, eyebrowHeadlineBodyLink.link] } else { - // Allow only radio button and link to be focused on. - var elements: [UIView] = [] - + // Only link. Manually add accessibility elements to ensure they are read in the right order. + var elements: [Any] = [] if let leftImageLabel = leftImage.accessibilityLabel, !leftImageLabel.isEmpty { elements.append(leftImage) } - - if let eyeBrowText = eyebrowHeadlineBodyLink.eyebrow.text, !eyeBrowText.isEmpty { - elements.append(eyebrowHeadlineBodyLink.eyebrow) + if let otherElements = eyebrowHeadlineBodyLink.getAccessibilityElements() { + elements.append(otherElements) } - - if let headlineText = eyebrowHeadlineBodyLink.headline.text, !headlineText.isEmpty { - elements.append(eyebrowHeadlineBodyLink.headline) - } - - if let bodyText = eyebrowHeadlineBodyLink.body.text, !bodyText.isEmpty { - elements.append(eyebrowHeadlineBodyLink.body) - } - - if linkShowing { - elements.append(eyebrowHeadlineBodyLink.link) - } - accessibilityElements = elements } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaret.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaret.swift index 297ef31b..821becbe 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaret.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaret.swift @@ -48,8 +48,6 @@ import UIKit rightLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 902), for: .horizontal) addMolecule(stack) stack.restack() - isAccessibilityElement = true - updateAccessibilityLabel() } //-------------------------------------------------- @@ -78,7 +76,7 @@ import UIKit } func updateAccessibilityLabel() { - + isAccessibilityElement = true var message = "" if let leftImageLabel = leftImage.accessibilityLabel { @@ -94,5 +92,6 @@ import UIKit } accessibilityLabel = message + accessibilityTraits = (accessoryView != nil) ? .button : .none } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretBodyText.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretBodyText.swift index 0617b5e8..c416e536 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretBodyText.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretBodyText.swift @@ -58,10 +58,8 @@ import Foundation rightLabel.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 900), for: .horizontal) rightLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 900), for: .horizontal) rightLabel.numberOfLines = 1 - isAccessibilityElement = true addMolecule(stack) stack.restack() - updateAccessibilityLabel() } //-------------------------------------------------- @@ -93,7 +91,7 @@ import Foundation //-------------------------------------------------- func updateAccessibilityLabel() { - + isAccessibilityElement = true var message = "" if let leftImageLabel = leftImage.accessibilityLabel { @@ -113,5 +111,6 @@ import Foundation } accessibilityLabel = message + accessibilityTraits = (accessoryView != nil) ? .button : .none } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableNumberedListAllTextAndLinks.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableNumberedListAllTextAndLinks.swift index 6b133172..183514de 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableNumberedListAllTextAndLinks.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableNumberedListAllTextAndLinks.swift @@ -75,11 +75,14 @@ import Foundation // MARK: - Accessibility //-------------------------------------------------- - func getAccessibilityMessage() -> String { + func getAccessibilityMessage() -> String? { guard let leftLabel = leftLabel.text else { return eyebrowHeadlineBodyLink.getAccessibilityMessage() } - return leftLabel + ", " + eyebrowHeadlineBodyLink.getAccessibilityMessage() + guard let label = eyebrowHeadlineBodyLink.getAccessibilityMessage() else { + return leftLabel + } + return leftLabel + ", " + label } func updateAccessibilityLabel() { diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAllTextAndLinks.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAllTextAndLinks.swift index 5756d4f5..229a2456 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAllTextAndLinks.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAllTextAndLinks.swift @@ -89,16 +89,8 @@ import Foundation message += radioButtonLabel + ", " } - if let eyebrowLabel = eyebrowHeadlineBodyLink.eyebrow.text { - message += eyebrowLabel + ", " - } - - if let headlineLabel = eyebrowHeadlineBodyLink.headline.text { - message += headlineLabel + ", " - } - - if let bodyLabel = eyebrowHeadlineBodyLink.body.text { - message += bodyLabel + if let label = eyebrowHeadlineBodyLink.getAccessibilityMessage() { + message += label } let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0 @@ -112,18 +104,7 @@ import Foundation } else { // Allow only radio button and link to be focused on. radioButton.accessibilityLabel = message - - var elements: [UIView] = [] - - if !message.isEmpty { - elements.append(radioButton) - } - - if linkShowing { - elements.append(eyebrowHeadlineBodyLink.link) - } - - accessibilityElements = elements + accessibilityElements = [radioButton, eyebrowHeadlineBodyLink.link] } } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAndPaymentMethod.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAndPaymentMethod.swift index 523c6d4e..6cc26352 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAndPaymentMethod.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAndPaymentMethod.swift @@ -107,16 +107,8 @@ import UIKit 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 + if let label = eyebrowHeadlineBodyLink.getAccessibilityMessage() { + message += label } let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0 @@ -130,17 +122,7 @@ import UIKit } else { // Allow only radio button and link to be focused on. radioButton.accessibilityLabel = message - var elements: [UIView] = [] - - if !message.isEmpty { - elements.append(radioButton) - } - - if linkShowing { - elements.append(eyebrowHeadlineBodyLink.link) - } - - accessibilityElements = elements + accessibilityElements = [radioButton, eyebrowHeadlineBodyLink.link] } } } diff --git a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift index 8a4d6d38..12b42e9f 100644 --- a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift +++ b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift @@ -75,7 +75,7 @@ import UIKit //-------------------------------------------------- /// Returns the labels text in one message. - func getAccessibilityMessage() -> String { + func getAccessibilityMessage() -> String? { var message = "" if let eyebrowLabel = eyebrow.text { @@ -89,7 +89,7 @@ import UIKit if let bodyLabel = body.text { message += bodyLabel } - return message + return message.count > 0 ? message : nil } /// Returns an array of the appropriate accessibility elements.