Skip to content

add ellipsizeMode prop for text truncation and improve accessibility #3542

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

Merged
merged 7 commits into from
Mar 18, 2025
Prev Previous commit
replace ellipsizeMode with labelEllipsizeMode prop
  • Loading branch information
adids1221 committed Mar 18, 2025
commit 3d312055bf0f38325df5c14169d4706afe111a47
9 changes: 6 additions & 3 deletions src/components/avatar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export type AutoColorsProps = {
};

export type AvatarProps = Pick<AccessibilityProps, 'accessibilityLabel'> &
Pick<TextProps, 'ellipsizeMode'> &
PropsWithChildren<{
/**
* Adds fade in animation when Avatar image loads
Expand Down Expand Up @@ -122,6 +121,10 @@ export type AvatarProps = Pick<AccessibilityProps, 'accessibilityLabel'> &
* The label color
*/
labelColor?: string;
/*
* The ellipsize mode for the label, default is clip
*/
labelEllipsizeMode?: TextProps['ellipsizeMode'];
/**
* ribbon label to display on the avatar
*/
Expand Down Expand Up @@ -187,7 +190,7 @@ const Avatar = forwardRef<any, AvatarProps>((props: AvatarProps, ref: React.Forw
useAutoColors,
autoColorsConfig,
containerStyle,
ellipsizeMode = 'clip',
labelEllipsizeMode = 'clip',
onPress,
children
} = themeProps;
Expand Down Expand Up @@ -357,7 +360,7 @@ const Avatar = forwardRef<any, AvatarProps>((props: AvatarProps, ref: React.Forw
>
<View testID={`${testID}.container`} style={textContainerStyle}>
{!_.isUndefined(text) && (
<Text numberOfLines={1} ellipsizeMode={ellipsizeMode} style={textStyle} testID={`${testID}.label`}>
<Text numberOfLines={1} ellipsizeMode={labelEllipsizeMode} style={textStyle} testID={`${testID}.label`}>
{text}
</Text>
)}
Expand Down