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: adding aria-label alias for accessibilityLabel #34502

Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
83240e1
feat: adding alias for aria-label button
Viraj-10 Aug 26, 2022
b5746c5
feat: added example in rn tester and requested changes
Viraj-10 Aug 29, 2022
07c1352
feat: added aria-label alias in view
Viraj-10 Aug 29, 2022
a5411be
feat: added aria-label alias in pressable
Viraj-10 Aug 29, 2022
0f461e9
fix: spelling correction
Viraj-10 Aug 29, 2022
b2b898f
feat: added aria-label alias in text
Viraj-10 Aug 30, 2022
cb5c26d
fix: resolving merge conflict
Viraj-10 Aug 30, 2022
615d15a
fix: alphabetic order in props
Viraj-10 Aug 30, 2022
3d2fc23
feat: adding alias for aria-label button
Viraj-10 Aug 26, 2022
6cbda08
feat: added example in rn tester and requested changes
Viraj-10 Aug 29, 2022
b5604c0
rebase to react-native main
Viraj-10 Aug 30, 2022
53083cd
feat: added aria-label alias in pressable
Viraj-10 Aug 29, 2022
103e757
fix: spelling correction
Viraj-10 Aug 29, 2022
9c37a35
feat: added aria-label alias in text
Viraj-10 Aug 30, 2022
a646397
fix: alphabetic order in props
Viraj-10 Aug 30, 2022
bc54692
fix: merge conflict
Viraj-10 Aug 30, 2022
b6f0885
feat: adding alias for aria-label button
Viraj-10 Aug 26, 2022
56d844d
feat: added example in rn tester and requested changes
Viraj-10 Aug 29, 2022
4e1ade3
rebase to react-native main
Viraj-10 Aug 30, 2022
36ae9a9
feat: added aria-label alias in pressable
Viraj-10 Aug 29, 2022
40c4728
fix: spelling correction
Viraj-10 Aug 29, 2022
f41647d
feat: added aria-label alias in text
Viraj-10 Aug 30, 2022
5a68f08
fix: alphabetic order in props
Viraj-10 Aug 30, 2022
8c566ec
feat: added aria-label alias in view
Viraj-10 Aug 29, 2022
814194d
feat: added aria-label alias in pressable
Viraj-10 Aug 29, 2022
6395736
fix: spelling correction
Viraj-10 Aug 29, 2022
a24cd63
feat: added aria-label alias in text
Viraj-10 Aug 30, 2022
cef1874
fix: alphabetic order in props
Viraj-10 Aug 30, 2022
f3a8676
fix: test case for button props
Viraj-10 Aug 30, 2022
4df0835
rebase merge conflict
Viraj-10 Aug 31, 2022
2d39c55
Merge remote-tracking branch 'upstream/main' into feat/adding-aria-la…
Viraj-10 Sep 5, 2022
006a947
fix: removing duplicates
Viraj-10 Sep 5, 2022
ffeb392
feat: added aria-label alias in touchable
Viraj-10 Sep 5, 2022
1365d70
feat: added aria-label alias in image
Viraj-10 Sep 5, 2022
24f97c1
fix: merge conflict
Viraj-10 Sep 5, 2022
8b835f7
fix: test cases for ios
Viraj-10 Sep 5, 2022
81df035
fix: flow test fix
Viraj-10 Sep 5, 2022
0169fef
fix: spelling and types button and view
Viraj-10 Sep 7, 2022
5090026
rebase merge conflict
Viraj-10 Sep 8, 2022
99b2877
Merge remote-tracking branch 'upstream/main' into feat/adding-aria-la…
Viraj-10 Sep 8, 2022
3179b66
fix: test case pressable
Viraj-10 Sep 8, 2022
0dd6772
Merge remote-tracking branch 'upstream/main' into feat/adding-aria-la…
Viraj-10 Sep 9, 2022
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
9 changes: 8 additions & 1 deletion Libraries/Components/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ type ButtonProps = $ReadOnly<{|
importantForAccessibility?: ?('auto' | 'yes' | 'no' | 'no-hide-descendants'),
accessibilityHint?: ?string,
accessibilityLanguage?: ?Stringish,

/**
* Alias for accessibilityLabel https://reactnative.dev/docs/view#accessibilitylabel
* https://github.com/facebook/react-native/issues/34424
*/
'aria-label'?: ?string,
Viraj-10 marked this conversation as resolved.
Show resolved Hide resolved
|}>;

/**
Expand Down Expand Up @@ -270,6 +276,7 @@ class Button extends React.Component<ButtonProps> {
render(): React.Node {
const {
accessibilityLabel,
'aria-label': ariaLabel,
importantForAccessibility,
color,
onPress,
Expand Down Expand Up @@ -333,7 +340,7 @@ class Button extends React.Component<ButtonProps> {
accessible={accessible}
accessibilityActions={accessibilityActions}
onAccessibilityAction={onAccessibilityAction}
accessibilityLabel={accessibilityLabel}
accessibilityLabel={ariaLabel || accessibilityLabel}
accessibilityHint={accessibilityHint}
accessibilityLanguage={accessibilityLanguage}
accessibilityRole="button"
Expand Down
8 changes: 8 additions & 0 deletions Libraries/Components/Pressable/Pressable.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ type Props = $ReadOnly<{|
* Duration to wait after press down before calling `onPressIn`.
*/
unstable_pressDelay?: ?number,
/**
* Web to Native Accessibilty props
* https://github.com/facebook/react-native/issues/34424
*/
'aria-label'?: ?string,
|}>;

/**
Expand All @@ -177,6 +182,7 @@ function Pressable(props: Props, forwardedRef): React.Node {
accessible,
android_disableSound,
android_ripple,
'aria-label': ariaLabel,
cancelable,
children,
delayHoverIn,
Expand Down Expand Up @@ -210,10 +216,12 @@ function Pressable(props: Props, forwardedRef): React.Node {
? {...props.accessibilityState, disabled}
: props.accessibilityState;

const accessibilityLabel = ariaLabel ?? props.accessibilityLabel;
const restPropsWithDefaults: React.ElementConfig<typeof View> = {
...restProps,
...android_rippleConfig?.viewProps,
accessible: accessible !== false,
accessibilityLabel,
accessibilityState,
focusable: focusable !== false,
hitSlop,
Expand Down
12 changes: 11 additions & 1 deletion Libraries/Components/View/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,20 @@ const View: React.AbstractComponent<
ViewProps,
React.ElementRef<typeof ViewNativeComponent>,
> = React.forwardRef(
({tabIndex, focusable, ...otherProps}: ViewProps, forwardedRef) => {
(
{
accessibilityLabel,
'aria-label': ariaLabel,
tabIndex,
focusable,
...otherProps
}: ViewProps,
forwardedRef,
) => {
return (
<TextAncestor.Provider value={false}>
<ViewNativeComponent
accessibilityLabel={ariaLabel ?? accessibilityLabel}
focusable={tabIndex !== undefined ? !tabIndex : focusable}
{...otherProps}
ref={forwardedRef}
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 @@ -452,6 +452,12 @@ export type ViewProps = $ReadOnly<{|
*/
accessibilityHint?: ?Stringish,

/**
* Alias for accessibilityLabel https://reactnative.dev/docs/view#accessibilitylabel
* https://github.com/facebook/react-native/issues/34424
*/
'aria-label'?: ?Stringish,

Viraj-10 marked this conversation as resolved.
Show resolved Hide resolved
/**
* Indicates to the accessibility services that the UI component is in
* a specific language. The provided string should be formatted following
Expand Down
4 changes: 4 additions & 0 deletions Libraries/Text/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ const Text: React.AbstractComponent<
> = React.forwardRef((props: TextProps, forwardedRef) => {
const {
accessible,
accessibilityLabel,
allowFontScaling,
'aria-label': ariaLabel,
ellipsizeMode,
onLongPress,
onPress,
Expand Down Expand Up @@ -180,6 +182,7 @@ const Text: React.AbstractComponent<
<NativeVirtualText
{...restProps}
{...eventHandlersForText}
accessibilityLabel={ariaLabel ?? accessibilityLabel}
isHighlighted={isHighlighted}
isPressable={isPressable}
numberOfLines={numberOfLines}
Expand All @@ -194,6 +197,7 @@ const Text: React.AbstractComponent<
{...eventHandlersForText}
disabled={_disabled}
accessible={_accessible}
accessibilityLabel={ariaLabel ?? accessibilityLabel}
accessibilityState={_accessibilityState}
allowFontScaling={allowFontScaling !== false}
ellipsizeMode={ellipsizeMode ?? 'tail'}
Expand Down
1 change: 1 addition & 0 deletions Libraries/Text/TextProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export type TextProps = $ReadOnly<{|
accessibilityLabel?: ?Stringish,
accessibilityRole?: ?AccessibilityRole,
accessibilityState?: ?AccessibilityState,
'aria-label'?: ?string,

/**
* Whether font should be scaled down automatically.
Expand Down
22 changes: 22 additions & 0 deletions packages/rn-tester/js/examples/Button/ButtonExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,28 @@ exports.examples = [
);
},
},
{
title: 'Button with aria-label="label"',
description: ('Note: This prop changes the text that a screen ' +
'reader announces (there are no visual differences).': string),
render: function (): React.Node {
return (
<RNTesterThemeContext.Consumer>
{theme => {
return (
<Button
onPress={() => onButtonPress('submitted')}
testID="aria_label_button"
color={theme.LinkColor}
title="Submit Application"
aria-label="Press to submit your application!"
/>
);
}}
</RNTesterThemeContext.Consumer>
);
},
},
{
title: 'Button with accessibilityState={{disabled: true}}',
description:
Expand Down
27 changes: 27 additions & 0 deletions packages/rn-tester/js/examples/Pressable/PressableExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ import {
Text,
Platform,
View,
Alert,
} from 'react-native';
import ReactNativeFeatureFlags from 'react-native/Libraries/ReactNative/ReactNativeFeatureFlags';

const {useEffect, useRef, useState} = React;

function onPressablePress(pressableName: string) {
Alert.alert(`Your application has been ${pressableName}!`);
}

const forceTouchAvailable =
(Platform.OS === 'ios' && Platform.constants.forceTouchAvailable) || false;

Expand Down Expand Up @@ -81,6 +86,20 @@ function TextOnPressBox() {
);
}

function PressableAriaLabel() {
return (
<View style={[styles.row, styles.centered]}>
<Pressable
style={styles.wrapper}
testID="pressable_aria_label"
aria-label="pressable with aria label"
accessibilityRole="button"
onPress={() => onPressablePress('pressed')}>
<Text style={styles.button}>Press Me</Text>
</Pressable>
</View>
);
}
function PressableFeedbackEvents() {
const [eventLog, setEventLog] = useState([]);

Expand Down Expand Up @@ -524,6 +543,14 @@ const examples = [
return <PressableDisabled />;
},
},
{
title: 'Pressable with aria-label="label"',
description: ('Note: This prop changes the text that a screen ' +
'reader announces (there are no visual differences).': string),
render: function (): React.Node {
return <PressableAriaLabel />;
},
},
];

if (ReactNativeFeatureFlags.shouldPressibilityUseW3CPointerEventsForHover()) {
Expand Down
12 changes: 12 additions & 0 deletions packages/rn-tester/js/examples/View/ViewExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,4 +600,16 @@ exports.examples = [
);
},
},
{
title: 'View with aria-label="label"',
render(): React.Node {
return (
<View
aria-label="Blue background View with Text"
style={{backgroundColor: '#527FE4', padding: 5}}>
<Text style={{fontSize: 11}}>Blue background</Text>
</View>
);
},
},
];