Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/role to accessibility role mapping #34538

82 changes: 81 additions & 1 deletion Libraries/Components/View/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,95 @@ const View: React.AbstractComponent<
React.ElementRef<typeof ViewNativeComponent>,
> = React.forwardRef(
(
{tabIndex, focusable, style, pointerEvents, ...otherProps}: ViewProps,
{
tabIndex,
focusable,
role,
accessibilityRole,
pointerEvents,
style,
...otherProps
}: ViewProps,
forwardedRef,
) => {
// Map role values to AccessibilityRole values
const roleToAccessibilityRoleMapping = {
madhav23bansal marked this conversation as resolved.
Show resolved Hide resolved
alert: 'alert',
alertdialog: undefined,
application: undefined,
article: undefined,
banner: undefined,
button: 'button',
cell: undefined,
checkbox: 'checkbox',
columnheader: undefined,
combobox: 'combobox',
complementary: undefined,
contentinfo: undefined,
definition: undefined,
dialog: undefined,
directory: undefined,
document: undefined,
feed: undefined,
figure: undefined,
form: undefined,
grid: 'grid',
group: undefined,
heading: 'header',
img: 'image',
link: 'link',
list: 'list',
listitem: undefined,
log: undefined,
main: undefined,
marquee: undefined,
math: undefined,
menu: 'menu',
menubar: 'menubar',
menuitem: 'menuitem',
meter: undefined,
navigation: undefined,
none: 'none',
note: undefined,
presentation: 'none',
progressbar: 'progressbar',
radio: 'radio',
radiogroup: 'radiogroup',
region: undefined,
row: undefined,
rowgroup: undefined,
rowheader: undefined,
scrollbar: 'scrollbar',
searchbox: 'search',
separator: undefined,
slider: 'adjustable',
spinbutton: 'spinbutton',
status: undefined,
summary: 'summary',
switch: 'switch',
tab: 'tab',
table: undefined,
tablist: 'tablist',
tabpanel: undefined,
term: undefined,
timer: 'timer',
toolbar: 'toolbar',
tooltip: undefined,
tree: undefined,
treegrid: undefined,
treeitem: undefined,
};

const flattendStyle = flattenStyle(style);
const newPointerEvents = pointerEvents || flattendStyle?.pointerEvents;

return (
<TextAncestor.Provider value={false}>
<ViewNativeComponent
focusable={tabIndex !== undefined ? !tabIndex : focusable}
accessibilityRole={
role ? roleToAccessibilityRoleMapping[role] : accessibilityRole
}
{...otherProps}
style={style}
pointerEvents={newPointerEvents}
Expand Down
67 changes: 67 additions & 0 deletions Libraries/Components/View/ViewAccessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,73 @@ export type AccessibilityRole =
| 'toolbar'
| 'grid';

// Role types for web
export type Role =
| 'alert'
| 'alertdialog'
| 'application'
| 'article'
| 'banner'
| 'button'
| 'cell'
| 'checkbox'
| 'columnheader'
| 'combobox'
| 'complementary'
| 'contentinfo'
| 'definition'
| 'dialog'
| 'directory'
| 'document'
| 'feed'
| 'figure'
| 'form'
| 'grid'
| 'group'
| 'heading'
| 'img'
| 'link'
| 'list'
| 'listitem'
| 'log'
| 'main'
| 'marquee'
| 'math'
| 'menu'
| 'menubar'
| 'menuitem'
| 'meter'
| 'navigation'
| 'none'
| 'note'
| 'presentation'
| 'progressbar'
| 'radio'
| 'radiogroup'
| 'region'
| 'row'
| 'rowgroup'
| 'rowheader'
| 'scrollbar'
| 'searchbox'
| 'separator'
| 'slider'
| 'spinbutton'
| 'status'
| 'summary'
| 'switch'
| 'tab'
| 'table'
| 'tablist'
| 'tabpanel'
| 'term'
| 'timer'
| 'toolbar'
| 'tooltip'
| 'tree'
| 'treegrid'
| 'treeitem';

// the info associated with an accessibility action
export type AccessibilityActionInfo = $ReadOnly<{
name: string,
Expand Down
6 changes: 6 additions & 0 deletions Libraries/Components/View/ViewPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {EdgeInsetsOrSizeProp} from '../../StyleSheet/EdgeInsetsPropType';
import type {Node} from 'react';
import type {ViewStyleProp} from '../../StyleSheet/StyleSheet';
import type {
Role,
AccessibilityRole,
AccessibilityState,
AccessibilityValue,
Expand Down Expand Up @@ -466,6 +467,11 @@ export type ViewProps = $ReadOnly<{|
*/
accessibilityRole?: ?AccessibilityRole,

/**
* Alias for accessibilityRole
*/
role?: ?Role,

/**
* Indicates to accessibility services that UI Component is in a specific State.
*/
Expand Down