@@ -276,6 +276,7 @@ internal extension ESTabBar /* Actions */ {
276
276
}
277
277
}
278
278
279
+ self . updateAccessibilityLabels ( )
279
280
self . setNeedsLayout ( )
280
281
}
281
282
@@ -407,20 +408,30 @@ internal extension ESTabBar /* Actions */ {
407
408
408
409
for (idx, item) in tabBarItems. enumerated ( ) {
409
410
let container = self . containers [ idx]
410
- var accessibilityTitle = " "
411
+ container. accessibilityIdentifier = item. accessibilityIdentifier
412
+ container. accessibilityTraits = item. accessibilityTraits
411
413
412
- if let item = item as? ESTabBarItem {
413
- accessibilityTitle = item. accessibilityLabel ?? item. title ?? " "
414
- }
415
- if self . isMoreItem ( idx) {
416
- accessibilityTitle = NSLocalizedString ( " More_TabBarItem " , bundle: Bundle ( for: ESTabBarController . self) , comment: " " )
414
+ if item == selectedItem {
415
+ container. accessibilityTraits = container. accessibilityTraits. union ( . selected)
417
416
}
418
417
419
- let formatString = NSLocalizedString ( item == selectedItem ? " TabBarItem_Selected_AccessibilityLabel " : " TabBarItem_AccessibilityLabel " ,
420
- bundle: Bundle ( for: ESTabBarController . self) ,
421
- comment: " " )
422
- container. accessibilityIdentifier = item. accessibilityIdentifier
423
- container. accessibilityLabel = String ( format: formatString, accessibilityTitle, idx + 1 , tabBarItems. count)
418
+ if let explicitLabel = item. accessibilityLabel {
419
+ container. accessibilityLabel = explicitLabel
420
+ container. accessibilityHint = item. accessibilityHint ?? container. accessibilityHint
421
+ } else {
422
+ var accessibilityTitle = " "
423
+ if let item = item as? ESTabBarItem {
424
+ accessibilityTitle = item. accessibilityLabel ?? item. title ?? " "
425
+ }
426
+ if self . isMoreItem ( idx) {
427
+ accessibilityTitle = NSLocalizedString ( " More_TabBarItem " , bundle: Bundle ( for: ESTabBarController . self) , comment: " " )
428
+ }
429
+
430
+ let formatString = NSLocalizedString ( item == selectedItem ? " TabBarItem_Selected_AccessibilityLabel " : " TabBarItem_AccessibilityLabel " ,
431
+ bundle: Bundle ( for: ESTabBarController . self) ,
432
+ comment: " " )
433
+ container. accessibilityLabel = String ( format: formatString, accessibilityTitle, idx + 1 , tabBarItems. count)
434
+ }
424
435
425
436
}
426
437
}
0 commit comments