@@ -85,13 +85,15 @@ public class InputFieldView: UIView {
8585
8686 private let titleLabel = UILabel ( ) . then {
8787 $0. adjustsFontForContentSizeCategory = true
88+ $0. isAccessibilityElement = false
8889 }
8990
9091 private let contentView = UIView ( )
9192
9293 private let leftContainerImageView = UIImageView ( ) . then {
9394 $0. contentMode = . scaleAspectFit
9495 $0. setContentHuggingPriority ( . defaultHigh, for: . horizontal)
96+ $0. isAccessibilityElement = false
9597 }
9698
9799 private let textField = UITextField ( ) . then {
@@ -116,6 +118,7 @@ public class InputFieldView: UIView {
116118 private let hintLabel = UILabel ( ) . then {
117119 $0. adjustsFontForContentSizeCategory = true
118120 $0. numberOfLines = 2
121+ $0. isAccessibilityElement = false
119122 }
120123
121124 // MARK: - Variables
@@ -131,6 +134,7 @@ public class InputFieldView: UIView {
131134 set {
132135 textField. text = newValue
133136 editingChangedSubject. send ( newValue)
137+ accessibilityValue = newValue
134138 }
135139 }
136140
@@ -163,6 +167,61 @@ public class InputFieldView: UIView {
163167
164168 private let editingChangedSubject = PassthroughSubject < String , Never > ( )
165169 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+ }
166225
167226 // MARK: - Initializer
168227
@@ -189,6 +248,9 @@ private extension InputFieldView {
189248 addSubviews ( )
190249 setupConstraints ( )
191250 setupActionHandlers ( )
251+
252+ // Accessiblity will be handled by the UITextField itself
253+ self . isAccessibilityElement = false
192254 }
193255
194256 func setupAppearance( ) {
@@ -236,6 +298,8 @@ private extension InputFieldView {
236298
237299 hintLabel. textColor = standardAppearance. enabled? . hintColor
238300 hintLabel. text = hint
301+ hintLabel. isAccessibilityElement = false
302+ accessibilityHint = hint
239303
240304 textField. attributedPlaceholder = NSAttributedString (
241305 string: textField. placeholder ?? C . emptyString,
@@ -252,6 +316,8 @@ private extension InputFieldView {
252316
253317 hintLabel. textColor = standardAppearance. disabled? . hintColor
254318 hintLabel. text = hint
319+ hintLabel. isAccessibilityElement = false
320+ accessibilityHint = hint
255321
256322 textField. attributedPlaceholder = NSAttributedString (
257323 string: textField. placeholder ?? C . emptyString,
@@ -267,6 +333,8 @@ private extension InputFieldView {
267333
268334 hintLabel. textColor = standardAppearance. selected? . hintColor
269335 hintLabel. text = hint
336+ hintLabel. isAccessibilityElement = false
337+ accessibilityHint = hint
270338
271339 textField. attributedPlaceholder = NSAttributedString (
272340 string: textField. placeholder ?? C . emptyString,
@@ -282,6 +350,10 @@ private extension InputFieldView {
282350
283351 hintLabel. textColor = standardAppearance. failed? . hintColor
284352 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)
285357
286358 textField. attributedPlaceholder = NSAttributedString (
287359 string: textField. placeholder ?? C . emptyString,
@@ -399,6 +471,12 @@ private extension InputFieldView {
399471 eyeButton. isHidden = false
400472 eyeButton. setImage ( eyeImage, for: . normal)
401473 textField. isSecureTextEntry = isSecure
474+ eyeButton. accessibilityLabel = isSecure
475+ ? showPasswordAccessibilityLabel
476+ : hidePasswordAccessibilityLabel
477+ eyeButton. accessibilityIdentifier = isSecure
478+ ? " show "
479+ : " hide "
402480 }
403481
404482 func trimWhitespaceIfAllowed( ) {
@@ -593,6 +671,9 @@ public extension InputFieldView {
593671
594672 /// Text
595673 textField. text = model. text
674+ accessibilityValue = textField. text
675+ accessibilityHint = hint
676+ accessibilityLabel = titleLabel. text
596677 }
597678
598679 func fail( with errorMessage: String ? ) {
0 commit comments