Skip to content

Commit b60f533

Browse files
Max Polevymeta-codesync[bot]
authored andcommitted
Respect accessibilityElementsHidden in recursive label aggregation (#55134)
Summary: Pull Request resolved: #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
1 parent 2a776b1 commit b60f533

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,10 @@ + (void)collectAccessibilityElements:(UIView *)view
13601360
// Result string is initialized lazily to prevent useless but costly allocations.
13611361
NSMutableString *result = nil;
13621362
for (UIView *subview in view.subviews) {
1363+
// Skip subviews that have accessibilityElementsHidden set to YES
1364+
if (subview.accessibilityElementsHidden) {
1365+
continue;
1366+
}
13631367
NSString *label = subview.accessibilityLabel;
13641368
if (!label) {
13651369
label = RCTRecursiveAccessibilityLabel(subview);

packages/react-native/React/Views/RCTView.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ - (UIView *)react_findClipView
9292
// Result string is initialized lazily to prevent useless but costly allocations.
9393
NSMutableString *str = nil;
9494
for (UIView *subview in view.subviews) {
95+
// Skip subviews that have accessibilityElementsHidden set to YES
96+
if (subview.accessibilityElementsHidden) {
97+
continue;
98+
}
9599
NSString *label = subview.accessibilityLabel;
96100
if (!label) {
97101
label = RCTRecursiveAccessibilityLabel(subview);

0 commit comments

Comments
 (0)