From daaeee4df37798e003726a53c2fbc31e2025cce9 Mon Sep 17 00:00:00 2001 From: Ritchie Jacobs Date: Thu, 4 Aug 2022 13:07:11 +0200 Subject: [PATCH 1/2] fix(image): allow empty string for alt and title property --- index.d.ts | 4 ++-- src/components/image.js | 5 ++++- src/utils.js | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/index.d.ts b/index.d.ts index 5619e4d..f3bd08c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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 */ diff --git a/src/components/image.js b/src/components/image.js index a3f7b4c..157c8c2 100644 --- a/src/components/image.js +++ b/src/components/image.js @@ -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 diff --git a/src/utils.js b/src/utils.js index a7c4255..47f08fe 100644 --- a/src/utils.js +++ b/src/utils.js @@ -172,7 +172,7 @@ function getNullableText(...args) { if (arg) return arg; - if (arg === false || arg === null) + if (arg === false || arg === null || arg === '') return null; } From f543221ca6c0845022e58300c0e44dd71933e379 Mon Sep 17 00:00:00 2001 From: Ritchie Jacobs Date: Thu, 4 Aug 2022 14:09:15 +0200 Subject: [PATCH 2/2] fix(utils): allow empty string attribute to be set for nullable text --- src/utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils.js b/src/utils.js index 47f08fe..d86a735 100644 --- a/src/utils.js +++ b/src/utils.js @@ -169,10 +169,10 @@ function setGroupedTimeout(fn, ttl) { export function getNullableText(...args) { for (const arg of args) { - if (arg) + if (arg || arg === '') return arg; - if (arg === false || arg === null || arg === '') + if (arg === false || arg === null) return null; }