Skip to content

Commit

Permalink
Consume the title and description of src assets
Browse files Browse the repository at this point in the history
  • Loading branch information
weotch committed Oct 28, 2024
1 parent 249361a commit 828a2bb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
28 changes: 28 additions & 0 deletions packages/contentful/cypress/component/ContentfulVisual.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,32 @@ describe('contentful visual entry props', () => {
.should('contain', videoAsset.url)
})

it('finds alt on src image', () => {
cy.mount(
<ContentfulVisual
src={{
...visualEntry,
alt: null,
}}
/>
);
cy.get("img").invoke("attr", "alt").should("eq", "Landscape gradient");
})

it("finds alt on src video", () => {
cy.mount(
<ContentfulVisual
src={{
...visualEntry,
image: null,
portraitImage: null,
alt: null,
}}
/>
);
cy.get("video")
.invoke("attr", "aria-label")
.should("eq", "Background loop description");
});

})
9 changes: 8 additions & 1 deletion packages/contentful/src/ContentfulVisual.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ export default function ContentfulVisual(
responsiveAspectCalculator :
getImageAspect(image || src?.image || src?.portraitImage)
)}
alt={ alt || src?.alt || makeAssetAlt(image) || makeAssetAlt(video)}
alt={
alt
|| src?.alt
|| makeAssetAlt(src?.image)
|| makeAssetAlt(image)
|| makeAssetAlt(src?.video)
|| makeAssetAlt(video)
}
/>
)
}
Expand Down

0 comments on commit 828a2bb

Please sign in to comment.