@@ -20,11 +20,15 @@ extension NSObject {
20
20
21
21
/// Returns a tuple consisting of the `description` and (optionally) a `hint` that VoiceOver will read for the object.
22
22
func accessibilityDescription( context: AccessibilityHierarchyParser . Context ? ) -> ( description: String , hint: String ? ) {
23
- var accessibilityDescription = accessibilityLabelOverride ( for: context) ?? accessibilityLabel ?? " "
23
+ let strings = Strings ( locale: accessibilityLanguage)
24
+
25
+ var accessibilityDescription =
26
+ accessibilityLabelOverride ( for: context) ??
27
+ ( hidesAccessibilityLabel ( backDescriptor: strings. backDescriptor) ? " " :
28
+ accessibilityLabel ?? " " )
24
29
25
30
var hintDescription = accessibilityHint? . nonEmpty ( )
26
31
27
- let strings = Strings ( locale: accessibilityLanguage)
28
32
29
33
let numberFormatter = NumberFormatter ( )
30
34
if let localeIdentifier = accessibilityLanguage {
@@ -126,8 +130,9 @@ extension NSObject {
126
130
case " 2 " :
127
131
traitSpecifiers. append ( strings. switchButtonMixedStateName)
128
132
default :
129
- // When the switch button trait is set, unknown accessibility values are omitted from the description.
130
- break
133
+ if let accessibilityValue {
134
+ traitSpecifiers. append ( accessibilityValue)
135
+ }
131
136
}
132
137
}
133
138
@@ -307,6 +312,13 @@ extension NSObject {
307
312
return false
308
313
}
309
314
}
315
+
316
+ private func hidesAccessibilityLabel( backDescriptor: String ) -> Bool {
317
+ // To prevent duplication, Back Button elements omit their label if it matches the localized "Back" descriptor.
318
+ guard accessibilityTraits. contains ( . backButton) ,
319
+ let label = accessibilityLabel else { return false }
320
+ return label. lowercased ( ) == backDescriptor. lowercased ( )
321
+ }
310
322
311
323
// MARK: - Private Static Properties
312
324
@@ -325,6 +337,8 @@ extension NSObject {
325
337
let buttonTraitName : String
326
338
327
339
let backButtonTraitName : String
340
+
341
+ let backDescriptor : String
328
342
329
343
let tabTraitName : String
330
344
@@ -410,6 +424,11 @@ extension NSObject {
410
424
comment: " Description for the 'back button' accessibility trait " ,
411
425
locale: locale
412
426
)
427
+ self . backDescriptor = " Back " . localized (
428
+ key: " back.descriptor " ,
429
+ comment: " Descriptor for the 'back' portion of the 'back button' accessibility trait " ,
430
+ locale: locale
431
+ )
413
432
self . tabTraitName = " Tab. " . localized (
414
433
key: " trait.tab.description " ,
415
434
comment: " Description for the 'tab' accessibility trait " ,
0 commit comments