mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Announce collapsed state for expanded: false on iOS (#58748)
Summary:
On the new architecture, VoiceOver reads nothing for `aria-expanded={false}` / `accessibilityState={{expanded: false}}`, so a collapsed accordion header sounds like a plain button. `RCTViewComponentView` only adds "expanded" to the accessibility value when the state is true and has no branch for false. The old `RCTView` announces "collapsed" there, and so does TalkBack.
This adds the missing branch, reusing the same localized "collapsed" string `RCTView.m` already has. An unset `expanded` still adds nothing.
Fixes https://github.com/react/react-native/issues/58746
## Changelog:
[IOS] [FIXED] - VoiceOver announces "collapsed" for `aria-expanded={false}` on the new architecture
Pull Request resolved: https://github.com/react/react-native/pull/58748
Test Plan: Added XCTest cases to `RCTViewComponentViewTests.mm` for `expanded` true, false and unset. Ran the repo's clang-format on both files. I couldn't run the iOS tests locally (no Xcode on this machine), so they rely on CI.
Reviewed By: cipolleschi
Differential Revision: D122875216
Pulled By: zeyap
fbshipit-source-id: ecca5825fcb6443cbaca57a3998be1efac893c35
This commit is contained in:
1 parent
425a284165
commit
1db1d893b2
2 files changed
+42
-3
No files matched your search
+9
-3
@@ -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) {
|
||||
|
||||
@@ -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<bool> expanded)
|
||||
{
|
||||
RCTViewComponentView *view = [RCTViewComponentView new];
|
||||
auto props = std::make_shared<ViewProps>();
|
||||
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)
|
||||
|
||||
Reference in new issue
Block a user