diff --git a/src/components/Image/Image.tsx b/src/components/Image/Image.tsx index 20a3664399..c40097ecf4 100644 --- a/src/components/Image/Image.tsx +++ b/src/components/Image/Image.tsx @@ -13,7 +13,10 @@ export type ImageProps = React.ImgHTMLAttributes & { } & ({ href: string; title: string } | { href?: never; title?: never }); const Image = React.forwardRef( - ({ className, ...props }, forwardRef) => { + ( + { alt = "", className, isSrcLoading, href, title, onError, ...props }, + forwardRef + ) => { const ref = useRef(null); const [isError, setError] = useState(false); @@ -23,7 +26,7 @@ const Image = React.forwardRef( () => ref.current ); - if ((!props.src && !props.isSrcLoading) || isError) { + if ((!props.src && !isSrcLoading) || isError) { return ; } @@ -45,7 +48,8 @@ const Image = React.forwardRef( * 5. Component `Image` flickers as it transitions from displaying `ContentLoader` to displaying `img` * */ - const isLoading = !ref.current?.complete && props.isSrcLoading; + const isLoading = !ref.current?.complete && isSrcLoading; + const commonClasses = `${className} ${isLoading ? "hidden" : ""}`; return ( <> @@ -62,20 +66,13 @@ const Image = React.forwardRef( * wrapping the `img`. * */} - + {props.alt (props.onError ? props.onError(e) : setError(true))} + className={`object-contain ${commonClasses}`} + alt={alt} + onError={(e) => (onError ? onError(e) : setError(true))} + {...props} />