Respect accessibilityElementsHidden in recursive label aggregation (#55134)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/55134

When a parent View has `accessible={true}` on iOS, React Native recursively aggregates the `accessibilityLabel` values from all descendant Text components (or accessible components) to construct the parent's accessibility label for VoiceOver. However, this aggregation was **not respecting** the `accessibilityElementsHidden` prop, so any child elements with accessibility labels (even Text components marked with accessible={false}) were still being read aloud by VoiceOver.

This diff fixes the `RCTRecursiveAccessibilityLabel` function to skip subviews that have `accessibilityElementsHidden=YES`, ensuring that:
- Views marked with `accessibilityElementsHidden={true}` are properly excluded from label aggregation
- The behavior aligns with developer expectations when using this accessibility prop, since it is [described](https://reactnative.dev/docs/accessibility#accessibilityelementshidden-ios) as "similar to the Android property importantForAccessibility="no-hide-descendants".

Changelog:
[iOS][Fixed] - Ensure accessibilityElementsHidden prop is respected in recursive accessibility label aggregation

Reviewed By: joevilches

Differential Revision: D90420237

fbshipit-source-id: 5cac5290f4291b69a1a7dcad0d5cc118822d0052
This commit is contained in:
Max Polevy authored and meta-codesync[bot] committed 2026-01-12 15:26:14 -08:00
1 parent 2a776b1f65
commit b60f533acc
2 files changed
+8

No files matched your search

@@ -1360,6 +1360,10 @@ static NSString *RCTRecursiveAccessibilityLabel(UIView *view)
// Result string is initialized lazily to prevent useless but costly allocations.
NSMutableString *result = nil;
for (UIView *subview in view.subviews) {
// Skip subviews that have accessibilityElementsHidden set to YES
if (subview.accessibilityElementsHidden) {
continue;
}
NSString *label = subview.accessibilityLabel;
if (!label) {
label = RCTRecursiveAccessibilityLabel(subview);
@@ -92,6 +92,10 @@ static NSString *RCTRecursiveAccessibilityLabel(UIView *view)
// Result string is initialized lazily to prevent useless but costly allocations.
NSMutableString *str = nil;
for (UIView *subview in view.subviews) {
// Skip subviews that have accessibilityElementsHidden set to YES
if (subview.accessibilityElementsHidden) {
continue;
}
NSString *label = subview.accessibilityLabel;
if (!label) {
label = RCTRecursiveAccessibilityLabel(subview);