@@ -85,13 +85,15 @@ public class InputFieldView: UIView {
85
85
86
86
private let titleLabel = UILabel ( ) . then {
87
87
$0. adjustsFontForContentSizeCategory = true
88
+ $0. isAccessibilityElement = false
88
89
}
89
90
90
91
private let contentView = UIView ( )
91
92
92
93
private let leftContainerImageView = UIImageView ( ) . then {
93
94
$0. contentMode = . scaleAspectFit
94
95
$0. setContentHuggingPriority ( . defaultHigh, for: . horizontal)
96
+ $0. isAccessibilityElement = false
95
97
}
96
98
97
99
private let textField = UITextField ( ) . then {
@@ -116,6 +118,7 @@ public class InputFieldView: UIView {
116
118
private let hintLabel = UILabel ( ) . then {
117
119
$0. adjustsFontForContentSizeCategory = true
118
120
$0. numberOfLines = 2
121
+ $0. isAccessibilityElement = false
119
122
}
120
123
121
124
// MARK: - Variables
@@ -131,6 +134,7 @@ public class InputFieldView: UIView {
131
134
set {
132
135
textField. text = newValue
133
136
editingChangedSubject. send ( newValue)
137
+ accessibilityValue = newValue
134
138
}
135
139
}
136
140
@@ -163,6 +167,61 @@ public class InputFieldView: UIView {
163
167
164
168
private let editingChangedSubject = PassthroughSubject < String , Never > ( )
165
169
private( set) public lazy var editingChangedPublisher = editingChangedSubject. eraseToAnyPublisher ( )
170
+
171
+ // MARK: - Accessibility
172
+
173
+ public override var accessibilityIdentifier : String ? {
174
+ get {
175
+ textField. accessibilityIdentifier
176
+ } set {
177
+ textField. accessibilityIdentifier = newValue
178
+ }
179
+ }
180
+
181
+ public override var accessibilityLabel : String ? {
182
+ get {
183
+ textField. accessibilityLabel
184
+ } set {
185
+ textField. accessibilityLabel = newValue
186
+ }
187
+ }
188
+
189
+ public override var accessibilityHint : String ? {
190
+ get {
191
+ textField. accessibilityHint
192
+ } set {
193
+ textField. accessibilityHint = newValue
194
+ }
195
+ }
196
+
197
+ public override var accessibilityValue : String ? {
198
+ get {
199
+ if isSecureTextEntry {
200
+ return textField. isSecureTextEntry ? textField. accessibilityValue : text
201
+ } else {
202
+ return textField. accessibilityValue
203
+ }
204
+ } set {
205
+ guard !isSecureTextEntry else { return }
206
+
207
+ textField. accessibilityValue = newValue
208
+ }
209
+ }
210
+
211
+ public var showPasswordAccessibilityLabel : String ? {
212
+ didSet {
213
+ guard textField. isSecureTextEntry else { return }
214
+
215
+ eyeButton. accessibilityLabel = showPasswordAccessibilityLabel
216
+ }
217
+ }
218
+ public var hidePasswordAccessibilityLabel : String ? {
219
+ didSet {
220
+ guard !textField. isSecureTextEntry else { return }
221
+
222
+ eyeButton. accessibilityLabel = hidePasswordAccessibilityLabel
223
+ }
224
+ }
166
225
167
226
// MARK: - Initializer
168
227
@@ -189,6 +248,9 @@ private extension InputFieldView {
189
248
addSubviews ( )
190
249
setupConstraints ( )
191
250
setupActionHandlers ( )
251
+
252
+ // Accessiblity will be handled by the UITextField itself
253
+ self . isAccessibilityElement = false
192
254
}
193
255
194
256
func setupAppearance( ) {
@@ -236,6 +298,8 @@ private extension InputFieldView {
236
298
237
299
hintLabel. textColor = standardAppearance. enabled? . hintColor
238
300
hintLabel. text = hint
301
+ hintLabel. isAccessibilityElement = false
302
+ accessibilityHint = hint
239
303
240
304
textField. attributedPlaceholder = NSAttributedString (
241
305
string: textField. placeholder ?? C . emptyString,
@@ -252,6 +316,8 @@ private extension InputFieldView {
252
316
253
317
hintLabel. textColor = standardAppearance. disabled? . hintColor
254
318
hintLabel. text = hint
319
+ hintLabel. isAccessibilityElement = false
320
+ accessibilityHint = hint
255
321
256
322
textField. attributedPlaceholder = NSAttributedString (
257
323
string: textField. placeholder ?? C . emptyString,
@@ -267,6 +333,8 @@ private extension InputFieldView {
267
333
268
334
hintLabel. textColor = standardAppearance. selected? . hintColor
269
335
hintLabel. text = hint
336
+ hintLabel. isAccessibilityElement = false
337
+ accessibilityHint = hint
270
338
271
339
textField. attributedPlaceholder = NSAttributedString (
272
340
string: textField. placeholder ?? C . emptyString,
@@ -282,6 +350,10 @@ private extension InputFieldView {
282
350
283
351
hintLabel. textColor = standardAppearance. failed? . hintColor
284
352
hintLabel. text = ( hint == nil ) ? ( nil ) : ( message ?? hint)
353
+
354
+ hintLabel. isAccessibilityElement = true
355
+ accessibilityHint = ( hint == nil ) ? ( nil ) : ( message ?? hint)
356
+ UIAccessibility . post ( notification: . layoutChanged, argument: hintLabel)
285
357
286
358
textField. attributedPlaceholder = NSAttributedString (
287
359
string: textField. placeholder ?? C . emptyString,
@@ -399,6 +471,12 @@ private extension InputFieldView {
399
471
eyeButton. isHidden = false
400
472
eyeButton. setImage ( eyeImage, for: . normal)
401
473
textField. isSecureTextEntry = isSecure
474
+ eyeButton. accessibilityLabel = isSecure
475
+ ? showPasswordAccessibilityLabel
476
+ : hidePasswordAccessibilityLabel
477
+ eyeButton. accessibilityIdentifier = isSecure
478
+ ? " show "
479
+ : " hide "
402
480
}
403
481
404
482
func trimWhitespaceIfAllowed( ) {
@@ -593,6 +671,9 @@ public extension InputFieldView {
593
671
594
672
/// Text
595
673
textField. text = model. text
674
+ accessibilityValue = textField. text
675
+ accessibilityHint = hint
676
+ accessibilityLabel = titleLabel. text
596
677
}
597
678
598
679
func fail( with errorMessage: String ? ) {
0 commit comments