From 78bd6be6ce98c375bf90b34333c1ff7abe675bb6 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 3 Mar 2023 16:31:31 -0600 Subject: [PATCH] added some accessibilty updates Signed-off-by: Matt Bruce --- VDS/Components/Buttons/Button/Button.swift | 3 + .../Buttons/Button/ButtonBase.swift | 2 - .../Buttons/ButtonGroup/ButtonGroup.swift | 2 - .../Buttons/TextLink/TextLink.swift | 7 +- .../Buttons/TextLinkCaret/TextLinkCaret.swift | 3 + VDS/Components/Checkbox/CheckboxGroup.swift | 2 - VDS/Components/Icon/Icon.swift | 3 + VDS/Components/Label/Label.swift | 9 +- .../RadioSwatch/RadioSwatchGroup.swift | 2 - VDS/Components/Tilelet/Tilelet.swift | 102 +++++++++--------- VDS/Components/TitleLockup/TitleLockup.swift | 8 +- 11 files changed, 78 insertions(+), 65 deletions(-) diff --git a/VDS/Components/Buttons/Button/Button.swift b/VDS/Components/Buttons/Button/Button.swift index f7274092..0b52e0fe 100644 --- a/VDS/Components/Buttons/Button/Button.swift +++ b/VDS/Components/Buttons/Button/Button.swift @@ -118,6 +118,9 @@ open class Button: ButtonBase, Useable { open override func setup() { super.setup() + isAccessibilityElement = true + accessibilityTraits = .button + //only 1 of the 2 widths can be on at the same time widthConstraint = widthAnchor.constraint(equalToConstant: 0) minWidthConstraint = widthAnchor.constraint(greaterThanOrEqualToConstant: size.minimumWidth) diff --git a/VDS/Components/Buttons/Button/ButtonBase.swift b/VDS/Components/Buttons/Button/ButtonBase.swift index 890b8f9c..4eeec6ee 100644 --- a/VDS/Components/Buttons/Button/ButtonBase.swift +++ b/VDS/Components/Buttons/Button/ButtonBase.swift @@ -109,7 +109,6 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab backgroundColor = .clear translatesAutoresizingMaskIntoConstraints = false accessibilityCustomActions = [] - accessibilityTraits = .staticText setup() setupDidChangeEvent() updateView() @@ -130,7 +129,6 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab disabled = false text = nil accessibilityCustomActions = [] - accessibilityTraits = .button } //-------------------------------------------------- diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift index 29e40432..7b6c8bdd 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift @@ -133,8 +133,6 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega //-------------------------------------------------- open override func setup() { super.setup() - isAccessibilityElement = true - accessibilityTraits = .button addSubview(collectionView) collectionView.pinToSuperView() } diff --git a/VDS/Components/Buttons/TextLink/TextLink.swift b/VDS/Components/Buttons/TextLink/TextLink.swift index 0451d600..a253a406 100644 --- a/VDS/Components/Buttons/TextLink/TextLink.swift +++ b/VDS/Components/Buttons/TextLink/TextLink.swift @@ -73,7 +73,9 @@ open class TextLink: ButtonBase { //-------------------------------------------------- open override func setup() { super.setup() - + isAccessibilityElement = true + accessibilityTraits = .link + if let titleLabel { addSubview(line) line.pinLeading(titleLabel.leadingAnchor) @@ -88,7 +90,8 @@ open class TextLink: ButtonBase { super.reset() size = .large accessibilityCustomActions = [] - accessibilityTraits = .staticText + isAccessibilityElement = true + accessibilityTraits = .link } //-------------------------------------------------- diff --git a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift index 7c2f9fbd..f6ba09a0 100644 --- a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift +++ b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift @@ -231,6 +231,9 @@ internal class CaretView: View { override open func setup() { super.setup() defaultState() + + isAccessibilityElement = true + accessibilityTraits = .link } //------------------------------------------------------ diff --git a/VDS/Components/Checkbox/CheckboxGroup.swift b/VDS/Components/Checkbox/CheckboxGroup.swift index 2cb7596b..6b5412f0 100644 --- a/VDS/Components/Checkbox/CheckboxGroup.swift +++ b/VDS/Components/Checkbox/CheckboxGroup.swift @@ -75,8 +75,6 @@ public class CheckboxGroupBase: SelectorGroupHandlerB open override func setup() { super.setup() - isAccessibilityElement = true - accessibilityTraits = .button addSubview(mainStackView) mainStackView.pinToSuperView() diff --git a/VDS/Components/Icon/Icon.swift b/VDS/Components/Icon/Icon.swift index dba2dab4..e988d27a 100644 --- a/VDS/Components/Icon/Icon.swift +++ b/VDS/Components/Icon/Icon.swift @@ -49,6 +49,9 @@ public class Icon: View { widthConstraint?.isActive = true backgroundColor = .clear + + isAccessibilityElement = true + accessibilityTraits = .image } open override func reset() { diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index 2a4aefd4..07680837 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -109,8 +109,6 @@ public class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable textPosition = .left text = nil attributedText = nil - accessibilityCustomActions = [] - accessibilityTraits = .staticText numberOfLines = 0 backgroundColor = .clear } @@ -125,9 +123,9 @@ public class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable font = textStyle.font if let text = text, let font = font, let textColor = textColor { - //clear the arrays holding actions accessibilityCustomActions = [] - + + //clear the arrays holding actions //create the primary string let startingAttributes = [NSAttributedString.Key.font: font, NSAttributedString.Key.foregroundColor: textColor] let mutableText = NSMutableAttributedString(string: text, attributes: startingAttributes) @@ -139,10 +137,11 @@ public class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable //set the attributed text attributedText = mutableText + accessibilityLabel = text } } } - + // MARK: - Private Attributes private func applyAttributes(_ mutableAttributedString: NSMutableAttributedString) { actions = [] diff --git a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift index 70dd38fc..751d11b3 100644 --- a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift +++ b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift @@ -82,8 +82,6 @@ public class RadioSwatchGroupBase: SelectorGroupSe open override func setup() { super.setup() - isAccessibilityElement = true - accessibilityTraits = .button addSubview(label) addSubview(collectionView) diff --git a/VDS/Components/Tilelet/Tilelet.swift b/VDS/Components/Tilelet/Tilelet.swift index c03cbd69..2c64e2a0 100644 --- a/VDS/Components/Tilelet/Tilelet.swift +++ b/VDS/Components/Tilelet/Tilelet.swift @@ -48,75 +48,75 @@ open class Tilelet: TileContainer { private var titleLockupContainerView = UIView().with { $0.translatesAutoresizingMaskIntoConstraints = false } - + private var badgeContainerView = UIView().with { $0.translatesAutoresizingMaskIntoConstraints = false } - + private let iconContainerView = UIView().with { $0.translatesAutoresizingMaskIntoConstraints = false $0.backgroundColor = .clear } - + //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- open var titleLockup = TitleLockup().with { let configs = [ TextStyle.DeviceSpacingConfig([.titleSmall, .boldTitleSmall], - neighboring: [ - .bodySmall, .boldBodySmall, - .bodyMedium, .boldBodyMedium - ], - spacing: 8.0, - deviceType: .iPhone), + neighboring: [ + .bodySmall, .boldBodySmall, + .bodyMedium, .boldBodyMedium + ], + spacing: 8.0, + deviceType: .iPhone), TextStyle.DeviceSpacingConfig([.titleMedium, .boldTitleMedium, - .titleLarge, .boldTitleLarge], - neighboring: [ - .bodySmall, .boldBodySmall, - .bodyMedium, .boldBodyMedium, - .bodyLarge, .boldBodyLarge], - spacing: 8.0, - deviceType: .iPhone), + .titleLarge, .boldTitleLarge], + neighboring: [ + .bodySmall, .boldBodySmall, + .bodyMedium, .boldBodyMedium, + .bodyLarge, .boldBodyLarge], + spacing: 8.0, + deviceType: .iPhone), TextStyle.DeviceSpacingConfig([.titleXLarge, .boldTitleXLarge], - neighboring: [ - .bodySmall, .boldBodySmall, - .bodyMedium, .boldBodyMedium, - .bodyLarge, .boldBodyLarge, - .titleMedium, .boldTitleMedium - ], - spacing: 12.0, - deviceType: .iPhone), + neighboring: [ + .bodySmall, .boldBodySmall, + .bodyMedium, .boldBodyMedium, + .bodyLarge, .boldBodyLarge, + .titleMedium, .boldTitleMedium + ], + spacing: 12.0, + deviceType: .iPhone), TextStyle.DeviceSpacingConfig([.titleSmall, .boldTitleSmall, - .titleMedium, .boldTitleMedium], - neighboring: [ - .bodySmall, .boldBodySmall, - .bodyMedium, .boldBodyMedium, - .bodyLarge, .boldBodyLarge - ], - spacing: 8.0, - deviceType: .iPad), + .titleMedium, .boldTitleMedium], + neighboring: [ + .bodySmall, .boldBodySmall, + .bodyMedium, .boldBodyMedium, + .bodyLarge, .boldBodyLarge + ], + spacing: 8.0, + deviceType: .iPad), TextStyle.DeviceSpacingConfig([.titleLarge, .boldTitleLarge], - neighboring: [ - .bodySmall, .boldBodySmall, - .bodyMedium, .boldBodyMedium, - .bodyLarge, .boldBodyLarge, - .titleSmall, .boldTitleSmall - ], - spacing: 12.0, - deviceType: .iPad), + neighboring: [ + .bodySmall, .boldBodySmall, + .bodyMedium, .boldBodyMedium, + .bodyLarge, .boldBodyLarge, + .titleSmall, .boldTitleSmall + ], + spacing: 12.0, + deviceType: .iPad), TextStyle.DeviceSpacingConfig([.titleXLarge, .boldTitleXLarge], - neighboring: [ - .bodyLarge, .boldBodyLarge, - .titleMedium, .boldTitleMedium - ], - spacing: 16.0, - deviceType: .iPad) + neighboring: [ + .bodyLarge, .boldBodyLarge, + .titleMedium, .boldTitleMedium + ], + spacing: 16.0, + deviceType: .iPad) ] @@ -213,6 +213,9 @@ open class Tilelet: TileContainer { color = .black addContentView(stackView) + isAccessibilityElement = true + accessibilityTraits = .staticText + //badge badgeContainerView.addSubview(badge) badge @@ -286,7 +289,7 @@ open class Tilelet: TileContainer { if let subTitleModel, !subTitleModel.text.isEmpty { showTitleLockup = true } - + if showTitleLockup { //flip the surface for the titleLockup titleLockup.surface = color == .black ? Surface.dark : Surface.light @@ -330,6 +333,9 @@ open class Tilelet: TileContainer { } else { removeFromSuperview(titleLockupContainerView) } + + accessibilityTraits = enabledHighlight ? .link : .staticText + accessibilityLabel = [titleModel?.text, subTitleModel?.text].compactMap({$0}).joined(separator: ", ") } fileprivate func updateIcons() { @@ -351,7 +357,7 @@ open class Tilelet: TileContainer { //iconContainer descriptiveIcon.isHidden = descriptiveIconModel == nil directionalIcon.isHidden = directionalIconModel == nil - + if showIconContainerView { //spacing before iconContainerView var view: UIView? diff --git a/VDS/Components/TitleLockup/TitleLockup.swift b/VDS/Components/TitleLockup/TitleLockup.swift index 2633c627..d0dc9562 100644 --- a/VDS/Components/TitleLockup/TitleLockup.swift +++ b/VDS/Components/TitleLockup/TitleLockup.swift @@ -203,7 +203,7 @@ open class TitleLockup: View { super.setup() isAccessibilityElement = true - accessibilityTraits = .button + accessibilityTraits = .staticText addSubview(stackView) stackView.spacing = 0.0 @@ -214,6 +214,7 @@ open class TitleLockup: View { //pin stackview to edges stackView.pinToSuperView() + } open override func reset() { @@ -236,7 +237,7 @@ open class TitleLockup: View { //-------------------------------------------------- open override func updateView() { super.updateView() - + let allLabelsTextPosition = textPosition.value var eyebrowTextIsEmpty = true var titleTextIsEmpty = true @@ -298,5 +299,8 @@ open class TitleLockup: View { eyebrowLabel.isHidden = eyebrowTextIsEmpty titleLabel.isHidden = titleTextIsEmpty subTitleLabel.isHidden = subTitleTextIsEmpty + + accessibilityLabel = [eyebrowModel?.text, titleModel?.text, subTitleModel?.text].compactMap({$0}).joined(separator: ", ") } + }