Skip to content
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 84 additions & 2 deletions Libraries/Components/View/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,94 @@ const View: React.AbstractComponent<
ViewProps,
React.ElementRef<typeof ViewNativeComponent>,
> = React.forwardRef(
({tabIndex, focusable, ...otherProps}: ViewProps, forwardedRef) => {
(
{tabIndex, focusable, role, accessibilityRole, ...otherProps}: ViewProps,
forwardedRef,
) => {
let restProps = {...otherProps};

// Map role values to AccessibilityRole values
const roleToAccessibilityRoleMapping = {
alert: 'alert',
button: 'button',
checkbox: 'checkbox',
combobox: 'combobox',
grid: 'grid',
heading: 'header',
img: 'image',
link: 'link',
list: 'list',
menu: 'menu',
menubar: 'menubar',
menuitem: 'menuitem',
none: 'none',
presentation: 'none',
progressbar: 'progressbar',
radio: 'radio',
radiogroup: 'radiogroup',
scrollbar: 'scrollbar',
searchbox: 'search',
slider: 'adjustable',
spinbutton: 'spinbutton',
summary: 'summary',
switch: 'switch',
tab: 'tab',
tablist: 'tablist',
timer: 'timer',
toolbar: 'toolbar',
tooltip: undefined,
feed: undefined,
math: undefined,
note: undefined,
application: undefined,
article: undefined,
cell: undefined,
columnheader: undefined,
definition: undefined,
directory: undefined,
document: undefined,
figure: undefined,
group: undefined,
listitem: undefined,
meter: undefined,
row: undefined,
rowgroup: undefined,
rowheader: undefined,
separator: undefined,
table: undefined,
term: undefined,
tabpanel: undefined,
treeitem: undefined,
tree: undefined,
treegrid: undefined,
banner: undefined,
complementary: undefined,
contentinfo: undefined,
form: undefined,
main: undefined,
navigation: undefined,
region: undefined,
log: undefined,
marquee: undefined,
status: undefined,
alertdialog: undefined,
dialog: undefined,
};

const _accessibilityRole = role
? roleToAccessibilityRoleMapping[role]
: accessibilityRole;

// set restProps is _accessibilityRole exists
if (_accessibilityRole) {
restProps = {...restProps, accessibilityRole: _accessibilityRole};
}

return (
<TextAncestor.Provider value={false}>
<ViewNativeComponent
focusable={tabIndex !== undefined ? !tabIndex : focusable}
{...otherProps}
{...restProps}
ref={forwardedRef}
/>
</TextAncestor.Provider>
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