Skip to content

Commit

Permalink
Merge pull request #695 from Financial-Times/cc/update-teaser-DAC-non…
Browse files Browse the repository at this point in the history
…-descriptive-image-link-02

CON-2077, CON-2078: Adds alt text to image of video teaser
  • Loading branch information
camillecroci committed Feb 3, 2023
2 parents 6d77e4c + c8bc614 commit 7629610
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions components/x-teaser/Props.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export interface Media {
url: string
width: number
height: number
altText?: string
}

export interface Indicators {
Expand Down
3 changes: 2 additions & 1 deletion components/x-teaser/__fixtures__/video.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"image": {
"url": "http://com.ft.imagepublish.upp-prod-eu.s3.amazonaws.com/a27ce49b-85b8-445b-b883-db6e2f533194",
"width": 1920,
"height": 1080
"height": 1080,
"altText": "Image alt text"
},
"video": {
"url": "https://next-media-api.ft.com/renditions/15218247321960/640x360.mp4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ exports[`x-teaser / snapshots renders a Hero teaser with video data 1`] = `
}
>
<img
alt=""
alt="Image alt text"
className="o-teaser__image"
src="https://www.ft.com/__origami/service/image/v2/images/raw/http%3A%2F%2Fcom.ft.imagepublish.upp-prod-eu.s3.amazonaws.com%2Fa27ce49b-85b8-445b-b883-db6e2f533194?source=next&fit=scale-down&dpr=2&width=340"
/>
Expand Down Expand Up @@ -1647,7 +1647,7 @@ exports[`x-teaser / snapshots renders a HeroOverlay teaser with video data 1`] =
}
>
<img
alt=""
alt="Image alt text"
className="o-teaser__image"
src="https://www.ft.com/__origami/service/image/v2/images/raw/http%3A%2F%2Fcom.ft.imagepublish.upp-prod-eu.s3.amazonaws.com%2Fa27ce49b-85b8-445b-b883-db6e2f533194?source=next&fit=scale-down&dpr=2&width=640"
/>
Expand Down Expand Up @@ -2067,7 +2067,7 @@ exports[`x-teaser / snapshots renders a HeroVideo teaser with video data 1`] = `
}
>
<img
alt=""
alt="Image alt text"
className="o-teaser__image"
src="https://www.ft.com/__origami/service/image/v2/images/raw/http%3A%2F%2Fcom.ft.imagepublish.upp-prod-eu.s3.amazonaws.com%2Fa27ce49b-85b8-445b-b883-db6e2f533194?source=next&fit=scale-down&dpr=2&width=420"
/>
Expand Down Expand Up @@ -2781,7 +2781,7 @@ exports[`x-teaser / snapshots renders a Large teaser with video data 1`] = `
}
>
<img
alt=""
alt="Image alt text"
className="o-teaser__image"
src="https://www.ft.com/__origami/service/image/v2/images/raw/http%3A%2F%2Fcom.ft.imagepublish.upp-prod-eu.s3.amazonaws.com%2Fa27ce49b-85b8-445b-b883-db6e2f533194?source=next&fit=scale-down&dpr=2&width=340"
/>
Expand Down Expand Up @@ -3859,7 +3859,7 @@ exports[`x-teaser / snapshots renders a SmallHeavy teaser with video data 1`] =
}
>
<img
alt=""
alt="Image alt text"
className="o-teaser__image"
src="https://www.ft.com/__origami/service/image/v2/images/raw/http%3A%2F%2Fcom.ft.imagepublish.upp-prod-eu.s3.amazonaws.com%2Fa27ce49b-85b8-445b-b883-db6e2f533194?source=next&fit=scale-down&dpr=2&width=240"
/>
Expand Down Expand Up @@ -5131,7 +5131,7 @@ exports[`x-teaser / snapshots renders a TopStoryLandscape teaser with video data
}
>
<img
alt=""
alt="Image alt text"
className="o-teaser__image"
src="https://www.ft.com/__origami/service/image/v2/images/raw/http%3A%2F%2Fcom.ft.imagepublish.upp-prod-eu.s3.amazonaws.com%2Fa27ce49b-85b8-445b-b883-db6e2f533194?source=next&fit=scale-down&dpr=2&width=640"
/>
Expand Down
12 changes: 7 additions & 5 deletions components/x-teaser/src/Image.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ const aspectRatio = ({ width, height }) => {
return null
}

const NormalImage = ({ src }) => <img className="o-teaser__image" src={src} alt="" />
const NormalImage = ({ src, alt }) => <img className="o-teaser__image" src={src} alt={alt} />

const LazyImage = ({ src, lazyLoad }) => {
const LazyImage = ({ src, lazyLoad, alt }) => {
const lazyClassName = typeof lazyLoad === 'string' ? lazyLoad : ''
return <img className={`o-teaser__image ${lazyClassName}`} data-src={src} alt="" />
return <img className={`o-teaser__image ${lazyClassName}`} data-src={src} alt={alt} />
}

export default ({ relativeUrl, url, image, imageSize, imageLazyLoad, imageHighestQuality, ...props }) => {
Expand All @@ -32,6 +32,7 @@ export default ({ relativeUrl, url, image, imageSize, imageLazyLoad, imageHighes
const useImageService = !(image.url.startsWith('data:') || image.url.startsWith('blob:'))
const options = imageSize === 'XXL' && imageHighestQuality ? { quality: 'highest' } : {}
const imageSrc = useImageService ? imageService(image.url, ImageSizes[imageSize], options) : image.url
const alt = (image.altText || '').trim()
const ImageComponent = imageLazyLoad ? LazyImage : NormalImage

return (
Expand All @@ -43,9 +44,10 @@ export default ({ relativeUrl, url, image, imageSize, imageLazyLoad, imageHighes
'data-trackable': 'image-link',
tabIndex: '-1',
'aria-hidden': 'true'
}}>
}}
>
<div className="o-teaser__image-placeholder" style={{ paddingBottom: aspectRatio(image) }}>
<ImageComponent src={imageSrc} lazyLoad={imageLazyLoad} />
<ImageComponent src={imageSrc} lazyLoad={imageLazyLoad} alt={alt} />
</div>
</Link>
</div>
Expand Down

0 comments on commit 7629610

Please sign in to comment.