Skip to content

Commit d9445a7

Browse files
M-i-k-e-lethanshar
authored andcommitted
Fix Avatar and Badge accessibility (#580)
* Fix Avatar and Badge accessibility * Prevent red screen when label = '' * Move accessibility fix * Remove unused const
1 parent bebbb6c commit d9445a7

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

src/components/avatar/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,17 +314,17 @@ export default class Avatar extends PureBaseComponent {
314314
style={[this.getContainerStyle(), containerStyle]}
315315
testID={testID}
316316
onPress={onPress}
317-
accessible
317+
accessible={!_.isUndefined(onPress)}
318318
accessibilityLabel={'Avatar'}
319319
accessibilityRole={onPress ? 'button' : 'image'}
320320
{...this.extractAccessibilityProps()}
321321
>
322322
<View
323323
style={[this.getInitialsContainer(), {backgroundColor}, hasImage && this.styles.initialsContainerWithInset]}
324324
>
325-
<Text numberOfLines={1} style={[{fontSize}, this.styles.initials, {color}]}>
325+
{!_.isUndefined(label) && <Text numberOfLines={1} style={[{fontSize}, this.styles.initials, {color}]}>
326326
{label}
327-
</Text>
327+
</Text>}
328328
</View>
329329
{this.renderImage()}
330330
{this.renderBadge()}

src/components/badge/index.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export default class Badge extends PureBaseComponent {
103103
return {
104104
accessibilityLabel: icon ? 'badge' : label ? `${label} new items` : undefined,
105105
...this.extractAccessibilityProps(),
106-
accessible: true,
106+
accessible: !_.isUndefined(label),
107107
accessibilityRole: onPress ? 'button' : icon ? 'image' : 'text'
108108
};
109109
}
@@ -173,17 +173,20 @@ export default class Badge extends PureBaseComponent {
173173
}
174174

175175
renderLabel() {
176-
const {labelStyle} = this.props;
177-
return (
178-
<Text
179-
style={[this.styles.label, this.isSmallBadge() && this.styles.labelSmall, labelStyle]}
180-
allowFontScaling={false}
181-
numberOfLines={1}
182-
testID="badge"
183-
>
184-
{this.getFormattedLabel()}
185-
</Text>
186-
);
176+
const {labelStyle, label} = this.props;
177+
178+
if (label) {
179+
return (
180+
<Text
181+
style={[this.styles.label, this.isSmallBadge() && this.styles.labelSmall, labelStyle]}
182+
allowFontScaling={false}
183+
numberOfLines={1}
184+
testID="badge"
185+
>
186+
{this.getFormattedLabel()}
187+
</Text>
188+
);
189+
}
187190
}
188191

189192
renderIcon() {

0 commit comments

Comments
 (0)