Skip to content

Commit dceed2a

Browse files
committed
Announce collapsed state for expanded: false on iOS
1 parent a6c6fe9 commit dceed2a

2 files changed

Lines changed: 37 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
@@ -1618,6 +1618,10 @@ - (NSString *)accessibilityValue
16181618
[valueComponents
16191619
addObject:RCTLocalizedString("expanded", "a menu, dialog, accordian panel, or other widget which is expanded")];
16201620
}
1621+
if (!accessibilityState.expanded.value_or(true)) {
1622+
[valueComponents addObject:RCTLocalizedString(
1623+
"collapsed", "a menu, dialog, accordian panel, or other widget which is collapsed")];
1624+
}
16211625

16221626
if (accessibilityState.busy) {
16231627
[valueComponents addObject:RCTLocalizedString("busy", "an element currently being updated or modified")];

‎packages/react-native/React/Tests/Mounting/RCTViewComponentViewTests.mm‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,39 @@ - (void)testViewWithoutRoleIsNotKeyboardFocusable
238238
XCTAssertFalse(view.canBecomeFocused);
239239
}
240240

241+
#pragma mark - accessibilityValue for expanded state
242+
243+
static RCTViewComponentView *makeViewWithExpandedState(std::optional<bool> expanded)
244+
{
245+
RCTViewComponentView *view = [RCTViewComponentView new];
246+
auto props = std::make_shared<ViewProps>();
247+
props->accessible = true;
248+
props->accessibilityRole = "button";
249+
AccessibilityState accessibilityState;
250+
accessibilityState.expanded = expanded;
251+
props->accessibilityState = accessibilityState;
252+
[view updateProps:props oldProps:ViewShadowNode::defaultSharedProps()];
253+
return view;
254+
}
255+
256+
- (void)testAccessibilityValueAnnouncesExpanded
257+
{
258+
RCTViewComponentView *view = makeViewWithExpandedState(true);
259+
XCTAssertEqualObjects(view.accessibilityValue, @"expanded");
260+
}
261+
262+
- (void)testAccessibilityValueAnnouncesCollapsed
263+
{
264+
RCTViewComponentView *view = makeViewWithExpandedState(false);
265+
XCTAssertEqualObjects(view.accessibilityValue, @"collapsed");
266+
}
267+
268+
- (void)testAccessibilityValueIsNilWithoutExpandedState
269+
{
270+
RCTViewComponentView *view = makeViewWithExpandedState(std::nullopt);
271+
XCTAssertNil(view.accessibilityValue);
272+
}
273+
241274
#pragma mark - outline style on square corners (#57841)
242275

243276
static RCTViewComponentView *makeViewWithOutlineStyle(OutlineStyle outlineStyle)

0 commit comments

Comments
 (0)