Accessibility

Familiar web accessibility APIs in a platform-agnostic form.

Accessibility in React Native for Web combines several separate web APIs into a cohesive system. Assistive technologies (e.g., VoiceOver, TalkBack screen readers) derive useful information about the structure, purpose, and interactivity of web apps from their HTML elements, attributes, and ARIA in HTML.


Accessibility Props API #

React Native for Web includes APIs for making accessible apps. The most common and well supported accessibility features of the Web are exposed as platform-agnostic accessibility* props.

accessibilityActiveDescendant ?string

Equivalent to aria-activedescendant.

accessibilityAtomic ?boolean

Equivalent to aria-atomic.

accessibilityAutoComplete ?string

Equivalent to aria-autocomplete.

accessibilityBusy ?boolean

Equivalent to aria-busy.

accessibilityChecked ?(boolean | "mixed")

Equivalent to aria-checked.

accessibilityColumnCount ?number

Equivalent to aria-colcount.

accessibilityColumnIndex ?number

Equivalent to aria-colindex.

accessibilityColumnSpan ?number

Equivalent to aria-colspan.

accessibilityControls ?(string | Array<string>)

Equivalent to aria-controls.

accessibilityCurrent ?(boolean | "page" | "step" | "location" | "date" | "time")

Equivalent to aria-current.

accessibilityDescribedBy ?(string | Array<string>)

Equivalent to aria-describedby.

accessibilityDetails ?string

Equivalent to aria-details.

accessibilityDisabled ?boolean

Equivalent to aria-disabled.

accessibilityErrorMessage ?string

Equivalent to aria-errormessage.

accessibilityExpanded ?boolean

Equivalent to aria-expanded.

accessibilityFlowTo ?(string | Array<string>)

Equivalent to aria-flowto.

accessibilityHasPopup ?string

Equivalent to aria-haspopup.

accessibilityHidden ?boolean

Equivalent to aria-hidden.

accessibilityInvalid ?boolean

Equivalent to aria-invalid.

accessibilityKeyShortcuts ?Array<string>

Equivalent to aria-keyshortcuts.

accessibilityLabel ?string

Equivalent to aria-label.

accessibilityLabelledBy ?(string | Array<string>)

Equivalent to aria-labelledby.

accessibilityLevel ?number

Equivalent to aria-level.

accessibilityLiveRegion ?("assertive" | "off" | "polite")

Equivalent to aria-live.

accessibilityModal ?boolean

Equivalent to aria-modal.

accessibilityMultiline ?boolean

Equivalent to aria-multiline.

accessibilityMultiSelectable ?boolean

Equivalent to aria-multiselectable.

accessibilityOrientation ?("horizontal" | "vertical")

Equivalent to aria-orientation.

accessibilityOwns ?(string | Array<string>)

Equivalent to aria-owns.

accessibilityPlaceholder ?string

Equivalent to aria-placeholder.

accessibilityPosInSet ?number

Equivalent to aria-posinset.

accessibilityPressed ?boolean

Equivalent to aria-pressed.

accessibilityReadOnly ?boolean

Equivalent to aria-readonly.

accessibilityRequired ?boolean

Equivalent to aria-required.

accessibilityRole ?boolean

Equivalent to role.

accessibilityRoleDescription ?string

Equivalent to aria-roledescription.

accessibilityRowCount ?number

Equivalent to aria-rowcount.

accessibilityRowIndex ?number

Equivalent to aria-rowindex.

accessibilityRowSpan ?number

Equivalent to aria-rowspan.

accessibilitySelected ?boolean

Equivalent to aria-selected.

accessibilitySetSize ?number

Equivalent to aria-setsize.

accessibilitySort ?("ascending" | "descending" | "none" | "other")

Equivalent to aria-sort.

accessibilityValueMax ?number

Equivalent to aria-valuemax.

accessibilityValueMin ?number

Equivalent to aria-valuemin.

accessibilityValueNow ?number

Equivalent to aria-valuenow.

accessibilityValueText ?string

Equivalent to aria-valuetext.


Accessibility patterns #

The Text and View components can be rendered as links. If the href prop is set, the element will render <a> tags without altering the presentation of the element.

<Text href="/" />
// <a href="/" ></a>

The hrefAttrs prop sets link-related attributes.

const hrefAttrs = { download: true, rel: "nofollow", target: "blank" };

<Text
href="/document.pdf"
hrefAttrs={hrefAttrs}
/>

// <a download href="/document.pdf" rel="nofollow" target="_blank"></a>

Keyboard focus #

The focusable prop determines whether a component is user-focusable and appears in the keyboard tab flow. This prop should be used instead of the accessible prop found in React Native for Android/iOS, which is not implemented by React Native for Web/Windows/macOS.

<View focusable={true} />
// <div tabindex="0"></div>

<Text focusable={false} href="/" />
// <a href="/" tabindex="-1"></a>

Did you know? Any element (including elements not in the keybaord tab flow) can be programmatically focused via UIManager.focus(viewRef.current).

Accessible HTML #

React Native for Web components express semantics exclusively via the accessibility* props which are equivalent to aria-* attributes. For example, accessibilityRole is equivalent to the HTML role attribute, accessibilityLabel is equivalent to aria-label, etc. (Additional compatibility with React Native accessibility props is also included.)

<View
accessibilityLabel="..."
accessibilityPressed={false}
accessibilityRole="menuitem"
nativeID="abc"
/>

/*
<div
aria-label="..."
aria-pressed="false"
id="abc"
role="menuitem"
/>
*/

Semantic HTML #

The value of the accessibilityRole prop is used to infer an analogous HTML element where appropriate. This is done to rely on well-supported native mechanisms for encoding semantics and accessibility information.

<View accessibilityRole="article">
<Text accessibilityRole="paragraph">This is an article</Text>
</View>
/*
<article>
<div role="paragraph">This is an article</div>
</article>
*/

The "paragraph" role isn’t mapped to a <p> tag because it’s an HTML conformance error to include block-level children within the element; both Text and View support block-level children.

If the "heading" role is combined with an accessibilityLevel, the equivalent HTML heading element is rendered. Otherwise, it is rendered as <h1>.

<Text accessibilityRole="heading" /> /* <h1> */
<Text accessibilityRole="heading" accessibilityLevel={2} /> /* <h2> */

Note: Avoid changing accessibilityRole values over time or after user actions. Generally, accessibility APIs do not provide a means of notifying assistive technologies if a role changes.

Updated
Edit
React Native for WebCopyright © Nicolas Gallagher and Facebook Inc.