Skip to content

Commit 3517bb1

Browse files
Nick LefeverSaadnajmi
Nick Lefever
authored andcommitted
[fabric][a11y] Add role mapping for desktop specific traits
Summary: Paper was rendering text as AXStaticText. This diff updates the `RCTParagraphComponentView` to propagate the same role in Fabric for text. This change will allow to select UI elements based on the text contents. Test Plan: Use the Accessibility Inspector in Zeratul with Fabric enabled. With the changes the text elements are presented in the a11y hierarchy with AXStaticText: {F1162808272} Reviewers: shawndempsey, chpurrer, #rn-desktop Reviewed By: chpurrer Differential Revision: https://phabricator.intern.facebook.com/D51736933 Tasks: T170938725
1 parent 68f9bc8 commit 3517bb1

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

packages/react-native/React/Fabric/RCTConversions.h

+55-1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ inline NSAccessibilityRole RCTUIAccessibilityRoleFromAccessibilityTraits(
130130
{
131131
using AccessibilityTraits = facebook::react::AccessibilityTraits;
132132
if ((accessibilityTraits & AccessibilityTraits::Button) != AccessibilityTraits::None) {
133+
if ((accessibilityTraits & AccessibilityTraits::Bar) != AccessibilityTraits::None) {
134+
return NSAccessibilityToolbarRole;
135+
}
136+
if ((accessibilityTraits & AccessibilityTraits::PopUp) != AccessibilityTraits::None) {
137+
return NSAccessibilityPopUpButtonRole;
138+
}
139+
if ((accessibilityTraits & AccessibilityTraits::Menu) != AccessibilityTraits::None) {
140+
return NSAccessibilityMenuButtonRole;
141+
}
133142
return NSAccessibilityButtonRole;
134143
}
135144
if ((accessibilityTraits & AccessibilityTraits::Link) != AccessibilityTraits::None) {
@@ -159,7 +168,52 @@ inline NSAccessibilityRole RCTUIAccessibilityRoleFromAccessibilityTraits(
159168
if ((accessibilityTraits & AccessibilityTraits::Switch) != AccessibilityTraits::None) {
160169
return NSAccessibilityCheckBoxRole;
161170
}
162-
171+
if ((accessibilityTraits & AccessibilityTraits::UpdatesFrequently) != AccessibilityTraits::None) {
172+
return NSAccessibilityProgressIndicatorRole;
173+
}
174+
if ((accessibilityTraits & AccessibilityTraits::ComboBox) != AccessibilityTraits::None) {
175+
return NSAccessibilityComboBoxRole;
176+
}
177+
if ((accessibilityTraits & AccessibilityTraits::Menu) != AccessibilityTraits::None) {
178+
if ((accessibilityTraits & AccessibilityTraits::Bar) != AccessibilityTraits::None) {
179+
return NSAccessibilityMenuBarRole;
180+
}
181+
if ((accessibilityTraits & AccessibilityTraits::Item) != AccessibilityTraits::None) {
182+
return NSAccessibilityMenuItemRole;
183+
}
184+
return NSAccessibilityMenuRole;
185+
}
186+
if ((accessibilityTraits & AccessibilityTraits::Radio) != AccessibilityTraits::None) {
187+
if ((accessibilityTraits & AccessibilityTraits::Group) != AccessibilityTraits::None) {
188+
return NSAccessibilityRadioGroupRole;
189+
}
190+
return NSAccessibilityRadioButtonRole;
191+
}
192+
if ((accessibilityTraits & AccessibilityTraits::ScrollBar) != AccessibilityTraits::None) {
193+
return NSAccessibilityScrollBarRole;
194+
}
195+
if ((accessibilityTraits & AccessibilityTraits::SpinButton) != AccessibilityTraits::None) {
196+
return NSAccessibilityIncrementorRole;
197+
}
198+
if ((accessibilityTraits & AccessibilityTraits::Tab) != AccessibilityTraits::None) {
199+
if ((accessibilityTraits & AccessibilityTraits::List) != AccessibilityTraits::None) {
200+
return NSAccessibilityTabGroupRole;
201+
}
202+
return NSAccessibilityButtonRole;
203+
}
204+
if ((accessibilityTraits & AccessibilityTraits::Disclosure) != AccessibilityTraits::None) {
205+
return NSAccessibilityDisclosureTriangleRole;
206+
}
207+
if ((accessibilityTraits & AccessibilityTraits::Group) != AccessibilityTraits::None) {
208+
return NSAccessibilityGroupRole;
209+
}
210+
if ((accessibilityTraits & AccessibilityTraits::List) != AccessibilityTraits::None) {
211+
return NSAccessibilityListRole;
212+
}
213+
if ((accessibilityTraits & AccessibilityTraits::Table) != AccessibilityTraits::None) {
214+
return NSAccessibilityTableRole;
215+
}
216+
163217
return NSAccessibilityUnknownRole;
164218
};
165219
#endif // macOS]

packages/react-native/ReactCommon/react/renderer/components/view/AccessibilityPrimitives.h

+15
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ enum class AccessibilityTraits : uint32_t {
3434
Header = (1 << 15),
3535
Switch = (1 << 16),
3636
TabBar = (1 << 17),
37+
// [macOS
38+
ComboBox = (1 << 18),
39+
Menu = (1 << 19),
40+
PopUp = (1 << 20),
41+
Bar = (1 << 21),
42+
Item = (1 << 22),
43+
Group = (1 << 23),
44+
List = (1 << 24),
45+
Tab = (1 << 25),
46+
Table = (1 << 26),
47+
Disclosure = (1 << 27),
48+
Radio = (1 << 28),
49+
ScrollBar = (1 << 29),
50+
SpinButton = (1 << 30),
51+
// macOS]
3752
};
3853

3954
constexpr enum AccessibilityTraits operator|(

0 commit comments

Comments
 (0)