updated accessibility elements

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-04-24 15:28:12 -05:00
parent 788fcb73ac
commit 90ec2fa8f2
2 changed files with 38 additions and 13 deletions

View File

@ -22,7 +22,7 @@ open class Tilelet: TileContainerBase<Tilelet.Padding> {
public enum Padding: String, DefaultValuing, CaseIterable {
case small
case large
public static var defaultValue: Self { .large }
public var value: CGFloat {
@ -63,7 +63,7 @@ open class Tilelet: TileContainerBase<Tilelet.Padding> {
public required init?(coder: NSCoder) {
super.init(coder: coder)
}
//--------------------------------------------------
// MARK: - Enums
//--------------------------------------------------
@ -207,7 +207,7 @@ open class Tilelet: TileContainerBase<Tilelet.Padding> {
open var directionalIcon = Icon().with {
$0.name = .rightArrow
}
private var _textWidth: TextWidth?
/// If provided, width of Button components will be rendered based on this value. If omitted, default button widths are rendered.
@ -270,7 +270,7 @@ open class Tilelet: TileContainerBase<Tilelet.Padding> {
_descriptiveIconModel = nil
setNeedsUpdate()
}
}
}
//--------------------------------------------------
// MARK: - Constraints
@ -288,7 +288,7 @@ open class Tilelet: TileContainerBase<Tilelet.Padding> {
internal var titleLockupEyebrowLabelHeightGreaterThanConstraint: NSLayoutConstraint?
internal var titleLockupTitleLabelHeightGreaterThanConstraint: NSLayoutConstraint?
internal var titleLockupSubTitleLabelHeightGreaterThanConstraint: NSLayoutConstraint?
//--------------------------------------------------
// MARK: - Overrides
//--------------------------------------------------
@ -299,9 +299,6 @@ open class Tilelet: TileContainerBase<Tilelet.Padding> {
color = .black
addContentView(stackView)
accessibilityTraits = .link
accessibilityElements = [badge, titleLockup, descriptiveIcon, directionalIcon]
//badge
badgeContainerView.addSubview(badge)
badge
@ -322,7 +319,7 @@ open class Tilelet: TileContainerBase<Tilelet.Padding> {
titleLockupBottomGreaterThanConstraint = titleLockupContainerView.bottomAnchor.constraint(greaterThanOrEqualTo: titleLockup.bottomAnchor)
titleLockupTopGreaterThanConstraint = titleLockup.topAnchor.constraint(greaterThanOrEqualTo: titleLockupContainerView.topAnchor)
titleLockupCenterYConstraint = titleLockup.centerYAnchor.constraint(equalTo: titleLockupContainerView.centerYAnchor)
iconContainerView.addSubview(descriptiveIcon)
iconContainerView.addSubview(directionalIcon)
@ -351,12 +348,12 @@ open class Tilelet: TileContainerBase<Tilelet.Padding> {
badge.label.setContentCompressionResistancePriority(UILayoutPriority(labelPriority-1), for: .vertical)
titleLockup.subTitleLabel.setContentCompressionResistancePriority(UILayoutPriority(labelPriority-2), for: .vertical)
titleLockup.eyebrowLabel.setContentCompressionResistancePriority(UILayoutPriority(labelPriority-3), for: .vertical)
titleLockup.titleLabel.setContentHuggingPriority(UILayoutPriority(labelPriority), for: .vertical)
badge.label.setContentHuggingPriority(UILayoutPriority(labelPriority-1), for: .vertical)
titleLockup.subTitleLabel.setContentHuggingPriority(UILayoutPriority(labelPriority-2), for: .vertical)
titleLockup.eyebrowLabel.setContentHuggingPriority(UILayoutPriority(labelPriority-3), for: .vertical)
/**
Added these constraints for:
At fixed width & height if all the labels(Badge, Eyebrow, Title, Subtitle) are having more number of lines then we should display atleast one line of content per label instead of pushing labels out of bounds.
@ -412,7 +409,21 @@ open class Tilelet: TileContainerBase<Tilelet.Padding> {
/// Used to update any Accessibility properties.
open override func updateAccessibility() {
super.updateAccessibility()
var elements = [Any]()
if badgeModel != nil {
elements.append(badge)
}
if titleModel != nil || subTitleModel != nil || eyebrowModel != nil {
elements.append(titleLockup)
}
if descriptiveIconModel != nil {
elements.append(descriptiveIcon)
}
if directionalIconModel != nil {
elements.append(directionalIcon)
}
accessibilityElements = elements.count > 0 ? elements : nil
setAccessibilityLabel(for: [badge.label, titleLockup.eyebrowLabel, titleLockup.titleLabel, titleLockup.subTitleLabel])
}

View File

@ -272,7 +272,21 @@ open class TitleLockup: View {
titleLabel.textColorConfiguration = textColorPrimaryConfiguration
accessibilityElements = [eyebrowLabel, titleLabel, subTitleLabel]
}
open override func updateAccessibility() {
super.updateAccessibility()
var elements = [Any]()
if eyebrowModel != nil {
elements.append(eyebrowLabel)
}
if titleModel != nil {
elements.append(titleLabel)
}
if subTitleModel != nil {
elements.append(subTitleLabel)
}
accessibilityElements = elements.count > 0 ? elements : nil
}
/// Resets to default settings.