Skip to content

Commit bffb414

Browse files
joevilchesfacebook-github-bot
authored andcommitted
Allow link role to be announced if its set on entire text in nested text (facebook#50236)
Summary: Pull Request resolved: facebook#50236 If you do something like ``` <Text> <Text accessibilityRole="link"> I am a link! </Text> </Text> ``` we do not announce "link". We skip any sort of spans on the entire text on iOS, which I feel like is not ideal. This case would be common enough, and users may not have access to the top level text component. Note Android correctly handles this already. Changelog: [iOS] [Fixed] - Correctly announce "link" on nested text if its the entire text element Reviewed By: javache Differential Revision: D71770798 fbshipit-source-id: 4a0781a95cb27cf244d6d2b1d1df8a0451964301
1 parent 0437c40 commit bffb414

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentAccessibilityProvider.mm

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,16 @@ - (instancetype)initWithString:(facebook::react::AttributedString)attributedStri
8181
enumerateAttribute:RCTTextAttributesAccessibilityRoleAttributeName
8282
frame:_frame
8383
usingBlock:^(CGRect fragmentRect, NSString *_Nonnull fragmentText, NSString *value) {
84-
if ([fragmentText isEqualToString:firstElement.accessibilityLabel]) {
85-
// The fragment is the entire paragraph. This is handled as `firstElement`.
84+
if ((![value isEqualToString:@"button"] && ![value isEqualToString:@"link"])) {
8685
return;
8786
}
88-
if ((![value isEqualToString:@"button"] && ![value isEqualToString:@"link"])) {
87+
if ([fragmentText isEqualToString:firstElement.accessibilityLabel]) {
88+
if ([value isEqualToString:@"link"]) {
89+
firstElement.accessibilityTraits |= UIAccessibilityTraitLink;
90+
} else if ([value isEqualToString:@"button"]) {
91+
firstElement.accessibilityTraits |= UIAccessibilityTraitButton;
92+
}
93+
// The fragment is the entire paragraph. This is handled as `firstElement`.
8994
return;
9095
}
9196
if ([value isEqualToString:@"button"] &&

0 commit comments

Comments
 (0)