From b60f533accc589ddff7fde8fbdaa65606b2cad85 Mon Sep 17 00:00:00 2001 From: Max Polevy Date: Mon, 12 Jan 2026 15:26:14 -0800 Subject: [PATCH] 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 --- .../Mounting/ComponentViews/View/RCTViewComponentView.mm | 4 ++++ packages/react-native/React/Views/RCTView.m | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm index 7ed3baaf122..9895b22dbfb 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm @@ -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); diff --git a/packages/react-native/React/Views/RCTView.m b/packages/react-native/React/Views/RCTView.m index 6d18765683e..0bc228f287d 100644 --- a/packages/react-native/React/Views/RCTView.m +++ b/packages/react-native/React/Views/RCTView.m @@ -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);