From dde32fd6a4fdd7cfae3f0f04d90c80184b4a63ac Mon Sep 17 00:00:00 2001 From: Damodaram Date: Thu, 29 Oct 2020 14:37:18 +0530 Subject: [PATCH] accessibility updated --- ...riableIconWithRightCaretAllTextLinks.swift | 53 +++++++++---------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinks.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinks.swift index 0bafed66..2031cdd3 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinks.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinks.swift @@ -16,7 +16,7 @@ public let rightLabel = Label(fontStyle: .RegularBodySmall) public let rightLabelStackItem: StackItem public var stack: Stack - + //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- @@ -86,48 +86,43 @@ //-------------------------------------------------- // MARK: - Accessibility //-------------------------------------------------- - + func getAccessibilityMessage() -> String? { - - guard let rightLabel = rightLabel.text else { - return eyebrowHeadlineBodyLink.getAccessibilityMessage() + var message = "" + if let leftImageLabel = leftImage.imageView.accessibilityLabel { + message += leftImageLabel + ", " } - - guard let label = eyebrowHeadlineBodyLink.getAccessibilityMessage() else { - return rightLabel + if let label = eyebrowHeadlineBodyLink.getAccessibilityMessage() { + message += label + ", " } - - return rightLabel + ", " + label + if let rightLabel = rightLabel.text { + message += rightLabel + } + return message } func updateAccessibilityLabel() { - let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0 + isAccessibilityElement = !linkShowing + accessibilityTraits = (isAccessibilityElement && accessoryView != nil) ? .button : .none - if !linkShowing && accessoryView == nil { - // Make whole cell focusable if one action - isAccessibilityElement = true + if !linkShowing { + // Make whole cell focusable if no link. accessibilityLabel = getAccessibilityMessage() + } else if let accessoryView = accessoryView { + // Both caret and link. Read all content on caret. + accessoryView.accessibilityLabel = getAccessibilityMessage() + accessibilityElements = [accessoryView, eyebrowHeadlineBodyLink.link] } else { - // Make buttons focusable. - isAccessibilityElement = false + // Only link. Manually add accessibility elements to ensure they are read in the right order. var elements: [Any] = [] - - if let accessoryView = accessoryView { - accessoryView.accessibilityLabel = eyebrowHeadlineBodyLink.getAccessibilityMessage() - elements.append(accessoryView) - } else { - rightLabel.accessibilityLabel = getAccessibilityMessage() + if let otherElements = eyebrowHeadlineBodyLink.getAccessibilityElements() { + elements.append(otherElements) } - - elements.append(rightLabel) - - if linkShowing { - elements.append(eyebrowHeadlineBodyLink.link) + if let rightLabelText = rightLabel.text, !rightLabelText.isEmpty { + elements.append(rightLabel) } - accessibilityElements = elements } } - }