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 61ef98f921c..5151aeadd69 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm @@ -1614,9 +1614,15 @@ static NSString *RCTRecursiveAccessibilityLabel(UIView *view) addObject:RCTLocalizedString( "mixed", "a checkbox, radio button, or other widget which is both checked and unchecked")]; } - if (accessibilityState.expanded.value_or(false)) { - [valueComponents - addObject:RCTLocalizedString("expanded", "a menu, dialog, accordian panel, or other widget which is expanded")]; + if (const auto expanded = accessibilityState.expanded; expanded.has_value()) { + if (expanded.value()) { + [valueComponents addObject:RCTLocalizedString( + "expanded", "a menu, dialog, accordian panel, or other widget which is expanded")]; + } else { + [valueComponents + addObject:RCTLocalizedString( + "collapsed", "a menu, dialog, accordian panel, or other widget which is collapsed")]; + } } if (accessibilityState.busy) { diff --git a/packages/react-native/React/Tests/Mounting/RCTViewComponentViewTests.mm b/packages/react-native/React/Tests/Mounting/RCTViewComponentViewTests.mm index 91e100d28df..1a5e58d91cd 100644 --- a/packages/react-native/React/Tests/Mounting/RCTViewComponentViewTests.mm +++ b/packages/react-native/React/Tests/Mounting/RCTViewComponentViewTests.mm @@ -238,6 +238,39 @@ static RCTViewComponentView *makeViewWithRole(bool accessible, const std::string XCTAssertFalse(view.canBecomeFocused); } +#pragma mark - accessibilityValue for expanded state + +static RCTViewComponentView *makeViewWithExpandedState(std::optional expanded) +{ + RCTViewComponentView *view = [RCTViewComponentView new]; + auto props = std::make_shared(); + props->accessible = true; + props->accessibilityRole = "button"; + AccessibilityState accessibilityState; + accessibilityState.expanded = expanded; + props->accessibilityState = accessibilityState; + [view updateProps:props oldProps:ViewShadowNode::defaultSharedProps()]; + return view; +} + +- (void)testAccessibilityValueAnnouncesExpanded +{ + RCTViewComponentView *view = makeViewWithExpandedState(true); + XCTAssertEqualObjects(view.accessibilityValue, @"expanded"); +} + +- (void)testAccessibilityValueAnnouncesCollapsed +{ + RCTViewComponentView *view = makeViewWithExpandedState(false); + XCTAssertEqualObjects(view.accessibilityValue, @"collapsed"); +} + +- (void)testAccessibilityValueIsNilWithoutExpandedState +{ + RCTViewComponentView *view = makeViewWithExpandedState(std::nullopt); + XCTAssertNil(view.accessibilityValue); +} + #pragma mark - outline style on square corners (#57841) static RCTViewComponentView *makeViewWithOutlineStyle(OutlineStyle outlineStyle)