Skip to content

Commit

Permalink
fix: change way to solve CLS in teaser images
Browse files Browse the repository at this point in the history
  • Loading branch information
juanSanchezAlcala committed Apr 5, 2024
1 parent d2a2627 commit cda6a2e
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions components/x-teaser/src/Image.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import Link from './Link'
*/
const aspectRatio = ({ width, height }) => {
if (typeof width === 'number' && typeof height === 'number') {
const ratio = (100 / width) * height
return ratio.toFixed(4) + '%'
return { aspectRatio: `${width}/${height}` }
}

return null
return {}
}

const NormalImage = ({ src, alt }) => <img className="o-teaser__image" src={src} alt={alt} />
Expand Down Expand Up @@ -46,7 +44,7 @@ export default ({ relativeUrl, url, image, imageSize, imageLazyLoad, imageHighes
'aria-hidden': 'true'
}}
>
<div className="o-teaser__image-placeholder" style={{ paddingBottom: aspectRatio(image) }}>
<div className="o-teaser__image-placeholder" style={{ ...aspectRatio(image) }}>
<ImageComponent src={imageSrc} lazyLoad={imageLazyLoad} alt={alt} />
</div>
</Link>
Expand Down

0 comments on commit cda6a2e

Please sign in to comment.