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: Add alt prop to Image component #34550

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion Libraries/Image/Image.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ const BaseImage = (props: ImagePropsType, forwardedRef) => {
? loadingIndicatorSource.uri
: null,
ref: forwardedRef,
accessibilityLabel: props['aria-label'] ?? props.accessibilityLabel,
accessible: props.alt !== undefined ? true : props.accessible,
accessibilityLabel:
props['aria-label'] ?? props.accessibilityLabel ?? props.alt,
accessibilityState: {
busy: props['aria-busy'] ?? props.accessibilityState?.busy,
checked: props['aria-checked'] ?? props.accessibilityState?.checked,
Expand Down
8 changes: 8 additions & 0 deletions Libraries/Image/Image.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,14 @@ export interface ImagePropsBase
* A static image to display while downloading the final image off the network.
*/
defaultSource?: ImageURISource | number | undefined;

/**
* The text that's read by the screen reader when the user interacts with
* the image.
*
* See https://reactnative.dev/docs/image#alt
*/
alt?: string | undefined;
}

export interface ImageProps extends ImagePropsBase {
Expand Down
3 changes: 2 additions & 1 deletion Libraries/Image/Image.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ const BaseImage = (props: ImagePropsType, forwardedRef) => {
<ImageViewNativeComponent
accessibilityState={_accessibilityState}
{...restProps}
accessibilityLabel={accessibilityLabel}
accessible={props.alt !== undefined ? true : props.accessible}
accessibilityLabel={accessibilityLabel ?? props.alt}
ref={forwardedRef}
style={style}
resizeMode={resizeMode}
Expand Down
9 changes: 8 additions & 1 deletion Libraries/Image/ImageProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import type {
import type {ViewProps} from '../Components/View/ViewPropTypes';
import type {Node, Ref} from 'react';
import typeof Image from './Image';
import type {DimensionValue} from '../StyleSheet/StyleSheetTypes';

export type ImageLoadEvent = SyntheticEvent<
$ReadOnly<{|
Expand Down Expand Up @@ -93,6 +92,14 @@ export type ImageProps = {|
*/
'aria-label'?: ?Stringish,

/**
* The text that's read by the screen reader when the user interacts with
* the image.
*
* See https://reactnative.dev/docs/image#alt
*/
alt?: ?Stringish,

/**
* blurRadius: the blur radius of the blur filter added to the image
*
Expand Down
Loading