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

fix(image): allow empty string for alt and title property #250

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ export interface ReactAvatarProps {
/**
* The alt attribute used on the avatar img tag. If not set we will fallback to either name or value
*/
alt?: string;
alt?: string | boolean;
/**
* The title attribute used on the avatar img tag. If not set we will fallback to either name or value
*/
title?: string;
title?: string | boolean;
/**
* Used in combination with `name` and `value`. Give the background a fixed color with a hex like for example #FF0000
*/
Expand Down
5 changes: 4 additions & 1 deletion src/components/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ export default
class AvatarImage extends React.PureComponent {

static propTypes = {
alt: PropTypes.string,
alt: PropTypes.oneOfType([
PropTypes.string,
PropTypes.bool
]),
title: PropTypes.oneOfType([
PropTypes.string,
PropTypes.bool
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function getNullableText(...args) {
if (arg)
return arg;

if (arg === false || arg === null)
if (arg === false || arg === null || arg === '')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been added to the if (arg) condition. I would consider an empty string to be a valid value that people might want to set.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

return null;
}

Expand Down