accessibility updated
This commit is contained in:
parent
dceb0e6c8f
commit
dde32fd6a4
@ -16,7 +16,7 @@
|
||||
public let rightLabel = Label(fontStyle: .RegularBodySmall)
|
||||
public let rightLabelStackItem: StackItem
|
||||
public var stack: Stack<StackModel>
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user