accessibility updated
This commit is contained in:
parent
dceb0e6c8f
commit
dde32fd6a4
@ -16,7 +16,7 @@
|
|||||||
public let rightLabel = Label(fontStyle: .RegularBodySmall)
|
public let rightLabel = Label(fontStyle: .RegularBodySmall)
|
||||||
public let rightLabelStackItem: StackItem
|
public let rightLabelStackItem: StackItem
|
||||||
public var stack: Stack<StackModel>
|
public var stack: Stack<StackModel>
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -86,48 +86,43 @@
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Accessibility
|
// MARK: - Accessibility
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
func getAccessibilityMessage() -> String? {
|
func getAccessibilityMessage() -> String? {
|
||||||
|
var message = ""
|
||||||
guard let rightLabel = rightLabel.text else {
|
if let leftImageLabel = leftImage.imageView.accessibilityLabel {
|
||||||
return eyebrowHeadlineBodyLink.getAccessibilityMessage()
|
message += leftImageLabel + ", "
|
||||||
}
|
}
|
||||||
|
if let label = eyebrowHeadlineBodyLink.getAccessibilityMessage() {
|
||||||
guard let label = eyebrowHeadlineBodyLink.getAccessibilityMessage() else {
|
message += label + ", "
|
||||||
return rightLabel
|
|
||||||
}
|
}
|
||||||
|
if let rightLabel = rightLabel.text {
|
||||||
return rightLabel + ", " + label
|
message += rightLabel
|
||||||
|
}
|
||||||
|
return message
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateAccessibilityLabel() {
|
func updateAccessibilityLabel() {
|
||||||
|
|
||||||
let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0
|
let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0
|
||||||
|
isAccessibilityElement = !linkShowing
|
||||||
|
accessibilityTraits = (isAccessibilityElement && accessoryView != nil) ? .button : .none
|
||||||
|
|
||||||
if !linkShowing && accessoryView == nil {
|
if !linkShowing {
|
||||||
// Make whole cell focusable if one action
|
// Make whole cell focusable if no link.
|
||||||
isAccessibilityElement = true
|
|
||||||
accessibilityLabel = getAccessibilityMessage()
|
accessibilityLabel = getAccessibilityMessage()
|
||||||
|
} else if let accessoryView = accessoryView {
|
||||||
|
// Both caret and link. Read all content on caret.
|
||||||
|
accessoryView.accessibilityLabel = getAccessibilityMessage()
|
||||||
|
accessibilityElements = [accessoryView, eyebrowHeadlineBodyLink.link]
|
||||||
} else {
|
} else {
|
||||||
// Make buttons focusable.
|
// Only link. Manually add accessibility elements to ensure they are read in the right order.
|
||||||
isAccessibilityElement = false
|
|
||||||
var elements: [Any] = []
|
var elements: [Any] = []
|
||||||
|
if let otherElements = eyebrowHeadlineBodyLink.getAccessibilityElements() {
|
||||||
if let accessoryView = accessoryView {
|
elements.append(otherElements)
|
||||||
accessoryView.accessibilityLabel = eyebrowHeadlineBodyLink.getAccessibilityMessage()
|
|
||||||
elements.append(accessoryView)
|
|
||||||
} else {
|
|
||||||
rightLabel.accessibilityLabel = getAccessibilityMessage()
|
|
||||||
}
|
}
|
||||||
|
if let rightLabelText = rightLabel.text, !rightLabelText.isEmpty {
|
||||||
elements.append(rightLabel)
|
elements.append(rightLabel)
|
||||||
|
|
||||||
if linkShowing {
|
|
||||||
elements.append(eyebrowHeadlineBodyLink.link)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
accessibilityElements = elements
|
accessibilityElements = elements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user