Skip to content

Commit eeff7b8

Browse files
committed
Set accessibility labels on the digit grouping segmented control
1 parent 9ed3357 commit eeff7b8

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Authenticator/Source/DisplayOptionsViewController.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ extension DisplayOptionsViewController {
114114
fileprivate var digitGroupingRowViewModel: DigitGroupingRowViewModel<DisplayOptions.Effect> {
115115
return DigitGroupingRowViewModel(
116116
title: "Digit Grouping",
117-
options: [(title: "•• •• ••", value: 2), (title: "••• •••", value: 3)],
117+
options: [
118+
(title: "•• •• ••", accessibilityLabel: "Groups of two digits", value: 2),
119+
(title: "••• •••", accessibilityLabel: "Groups of three digits", value: 3),
120+
],
118121
value: viewModel.digitGroupSize,
119122
changeAction: DisplayOptions.Effect.setDigitGroupSize
120123
)
@@ -123,19 +126,21 @@ extension DisplayOptionsViewController {
123126

124127
// MARK: Digit Grouping Row
125128

129+
// swiftlint:disable large_tuple
126130
struct DigitGroupingRowViewModel<Action> {
127131
let title: String
128-
let segments: [(title: String, action: Action)]
132+
let segments: [(title: String, accessibilityLabel: String, action: Action)]
129133
let selectedSegmentIndex: Int?
130134

131-
init<V: Equatable>(title: String, options: [(title: String, value: V)], value: V, changeAction: (V) -> Action) {
135+
init<V: Equatable>(title: String, options: [(title: String, accessibilityLabel: String, value: V)], value: V, changeAction: (V) -> Action) {
132136
self.title = title
133137
segments = options.map({ option in
134-
(title: option.title, action: changeAction(option.value))
138+
(title: option.title, accessibilityLabel: option.accessibilityLabel, action: changeAction(option.value))
135139
})
136140
selectedSegmentIndex = options.map({ $0.value }).index(of: value)
137141
}
138142
}
143+
// swiftlint:enable large_tuple
139144

140145
class DigitGroupingRowCell<Action>: UITableViewCell {
141146
private let titleLabel = UILabel()
@@ -165,6 +170,8 @@ class DigitGroupingRowCell<Action>: UITableViewCell {
165170
titleLabel.translatesAutoresizingMaskIntoConstraints = false
166171
contentView.addSubview(titleLabel)
167172

173+
accessibilityHint = "The digits of a password can be shown in different sized groups."
174+
168175
let font = UIFont.systemFont(ofSize: 40, weight: .light)
169176
let fontAttributes = [NSAttributedStringKey.font: font]
170177
segmentedControl.setTitleTextAttributes(fontAttributes, for: .normal)
@@ -213,6 +220,10 @@ class DigitGroupingRowCell<Action>: UITableViewCell {
213220
for i in viewModel.segments.indices {
214221
let segment = viewModel.segments[i]
215222
segmentedControl.insertSegment(withTitle: segment.title, at: i, animated: false)
223+
224+
// This is a hack to set the accessibility label on each segment, but for now it works.
225+
// If a future iOS update ever changes the internals of UISegmentedControl, this may break horribly.
226+
segmentedControl.subviews.last?.accessibilityLabel = segment.accessibilityLabel
216227
}
217228
// Store the action associated with each segment
218229
actions = viewModel.segments.map({ $0.action })

0 commit comments

Comments
 (0)