mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
f353119113
Summary: This adds the [aria-labelledby](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-labelledby) prop to the components where it's used as requested on https://github.com/facebook/react-native/issues/34424, equivalent [accessibilityLabelledBy](https://reactnative.dev/docs/accessibility#accessibilitylabelledby-android) ## Changelog [General] [Added] - Add aria-modal prop to basic component ## TestPlan - Enable talkback. - Open the RNTester app and navigate to the Api's tab - Go to the TextInput with aria-labelledby attribute section <img width="495" alt="Screenshot 2022-09-19 at 7 46 05 PM" src="https://user-images.githubusercontent.com/22423684/191038924-017dba93-ea7d-494d-ba6f-161e986f9b54.png"> Pull Request resolved: https://github.com/facebook/react-native/pull/34725 Reviewed By: lunaleaps Differential Revision: D40176143 Pulled By: lunaleaps fbshipit-source-id: 003d1ab27bfd01b5c6d4c58a4de501ec7966359d
190 lines
5.3 KiB
JavaScript
190 lines
5.3 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 flattenStyle from '../../StyleSheet/flattenStyle';
|
|
import TextAncestor from '../../Text/TextAncestor';
|
|
import ViewNativeComponent from './ViewNativeComponent';
|
|
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,
|
|
accessibilityLabel,
|
|
accessibilityLabelledBy,
|
|
accessibilityLiveRegion,
|
|
accessibilityRole,
|
|
accessibilityState,
|
|
accessibilityValue,
|
|
'aria-busy': ariaBusy,
|
|
'aria-checked': ariaChecked,
|
|
'aria-disabled': ariaDisabled,
|
|
'aria-expanded': ariaExpanded,
|
|
'aria-hidden': ariaHidden,
|
|
'aria-label': ariaLabel,
|
|
'aria-labelledby': ariaLabelledBy,
|
|
'aria-live': ariaLive,
|
|
'aria-selected': ariaSelected,
|
|
'aria-valuemax': ariaValueMax,
|
|
'aria-valuemin': ariaValueMin,
|
|
'aria-valuenow': ariaValueNow,
|
|
'aria-valuetext': ariaValueText,
|
|
focusable,
|
|
id,
|
|
importantForAccessibility,
|
|
nativeID,
|
|
pointerEvents,
|
|
role,
|
|
style,
|
|
tabIndex,
|
|
...otherProps
|
|
}: ViewProps,
|
|
forwardedRef,
|
|
) => {
|
|
const _accessibilityLabelledBy =
|
|
ariaLabelledBy?.split(/\s*,\s*/g) ?? accessibilityLabelledBy;
|
|
|
|
const _accessibilityState = {
|
|
busy: ariaBusy ?? accessibilityState?.busy,
|
|
checked: ariaChecked ?? accessibilityState?.checked,
|
|
disabled: ariaDisabled ?? accessibilityState?.disabled,
|
|
expanded: ariaExpanded ?? accessibilityState?.expanded,
|
|
selected: ariaSelected ?? accessibilityState?.selected,
|
|
};
|
|
|
|
const _accessibilityValue = {
|
|
max: ariaValueMax ?? accessibilityValue?.max,
|
|
min: ariaValueMin ?? accessibilityValue?.min,
|
|
now: ariaValueNow ?? accessibilityValue?.now,
|
|
text: ariaValueText ?? accessibilityValue?.text,
|
|
};
|
|
|
|
// 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
|
|
{...otherProps}
|
|
accessibilityLiveRegion={
|
|
ariaLive === 'off' ? 'none' : ariaLive ?? accessibilityLiveRegion
|
|
}
|
|
accessibilityLabel={ariaLabel ?? accessibilityLabel}
|
|
focusable={tabIndex !== undefined ? !tabIndex : focusable}
|
|
accessibilityState={_accessibilityState}
|
|
accessibilityRole={
|
|
role ? roleToAccessibilityRoleMapping[role] : accessibilityRole
|
|
}
|
|
accessibilityElementsHidden={
|
|
ariaHidden ?? accessibilityElementsHidden
|
|
}
|
|
accessibilityLabelledBy={_accessibilityLabelledBy}
|
|
accessibilityValue={_accessibilityValue}
|
|
importantForAccessibility={
|
|
ariaHidden === true
|
|
? 'no-hide-descendants'
|
|
: importantForAccessibility
|
|
}
|
|
nativeID={id ?? nativeID}
|
|
style={style}
|
|
pointerEvents={newPointerEvents}
|
|
ref={forwardedRef}
|
|
/>
|
|
</TextAncestor.Provider>
|
|
);
|
|
},
|
|
);
|
|
|
|
View.displayName = 'View';
|
|
|
|
module.exports = View;
|