mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
ebdb23c6e0
Summary: This adds the ` aria-hidden` prop to `Pressable`, `TouchableBounce`, `TouchableHighlight`, `TouchableNativeFeedback`, `TouchableOpacity`, `TouchableWithoutFeedback` and `View` components as requested on https://github.com/facebook/react-native/issues/34424, being an alias `importantforAccessibility='no-hide-descendants'` on Android and an alias for `accessibilityElementsHidden` on iOS. This PR also updates RNTester AccessibilityExample in order to facilitate the manual QA. ## Changelog [General] [Added] - Add aria-hidden prop to Pressable, View and Touchables components Pull Request resolved: https://github.com/facebook/react-native/pull/34552 Test Plan: 1. Open the RNTester app and navigate to the Accessibility page 2. Test the `aria-hidden` prop through the `View with hidden children from accessibility tree` section, this can be tested either by enabling Voice Over if you're using a real device or through the Accessibility Inspector if you're using a simulator https://user-images.githubusercontent.com/11707729/187814455-6937e33e-7edd-434e-b7d3-ee6c03f635ca.mov Reviewed By: NickGerleman Differential Revision: D39206245 Pulled By: jacdebug fbshipit-source-id: 551dc671fbcedc824f253e22b8d7753c466838c7
145 lines
3.7 KiB
JavaScript
145 lines
3.7 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @flow strict-local
|
|
*/
|
|
|
|
import type {ViewProps} from './ViewPropTypes';
|
|
|
|
import ViewNativeComponent from './ViewNativeComponent';
|
|
import TextAncestor from '../../Text/TextAncestor';
|
|
import flattenStyle from '../../StyleSheet/flattenStyle';
|
|
import * as React from 'react';
|
|
|
|
export type Props = ViewProps;
|
|
|
|
/**
|
|
* The most fundamental component for building a UI, View is a container that
|
|
* supports layout with flexbox, style, some touch handling, and accessibility
|
|
* controls.
|
|
*
|
|
* @see https://reactnative.dev/docs/view
|
|
*/
|
|
const View: React.AbstractComponent<
|
|
ViewProps,
|
|
React.ElementRef<typeof ViewNativeComponent>,
|
|
> = React.forwardRef(
|
|
(
|
|
{
|
|
accessibilityElementsHidden,
|
|
accessibilityRole,
|
|
'aria-hidden': ariaHidden,
|
|
focusable,
|
|
importantForAccessibility,
|
|
pointerEvents,
|
|
role,
|
|
style,
|
|
tabIndex,
|
|
...otherProps
|
|
}: ViewProps,
|
|
forwardedRef,
|
|
) => {
|
|
// Map role values to AccessibilityRole values
|
|
const roleToAccessibilityRoleMapping = {
|
|
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 flattenedStyle = flattenStyle(style);
|
|
const newPointerEvents = flattenedStyle?.pointerEvents || pointerEvents;
|
|
|
|
return (
|
|
<TextAncestor.Provider value={false}>
|
|
<ViewNativeComponent
|
|
focusable={tabIndex !== undefined ? !tabIndex : focusable}
|
|
accessibilityRole={
|
|
role ? roleToAccessibilityRoleMapping[role] : accessibilityRole
|
|
}
|
|
accessibilityElementsHidden={
|
|
ariaHidden ?? accessibilityElementsHidden
|
|
}
|
|
importantForAccessibility={
|
|
ariaHidden === true
|
|
? 'no-hide-descendants'
|
|
: importantForAccessibility
|
|
}
|
|
{...otherProps}
|
|
style={style}
|
|
pointerEvents={newPointerEvents}
|
|
ref={forwardedRef}
|
|
/>
|
|
</TextAncestor.Provider>
|
|
);
|
|
},
|
|
);
|
|
|
|
View.displayName = 'View';
|
|
|
|
module.exports = View;
|