Skip to content

Commit

Permalink
Update Picture.astro so it no longer passes height and width attribut…
Browse files Browse the repository at this point in the history
…es (#4797)

* Update Picture.astro

the image variable of getPicture contains a width and height property, which we usually require. In this case, the image is wrapped in a picture tag and the img tag itself should not have a width and height property as this will break the responsiveness of the image provided by the picture tag.

* added changeset

* fixing SSG picture tests that were expecting img dimensions

Co-authored-by: Tony Sullivan <[email protected]>
  • Loading branch information
smeevil and Tony Sullivan committed Sep 22, 2022
1 parent a5df3f3 commit 944d24e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/selfish-files-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/image': patch
---

Do not pass width and height to the img element when wrapped in a picture element
3 changes: 3 additions & 0 deletions packages/integrations/image/components/Picture.astro
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ const { image, sources } = await getPicture({
background,
position,
});
delete image.width;
delete image.height;
---

<picture {...attrs}>
Expand Down
4 changes: 0 additions & 4 deletions packages/integrations/image/test/picture-ssg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,6 @@ describe('SSG pictures - build', function () {
const image = $(`${id} img`);

expect(image.attr('src')).to.match(regex);
expect(image.attr('width')).to.equal(size.width.toString());
expect(image.attr('height')).to.equal(size.height.toString());
expect(image.attr('alt')).to.equal(alt);

verifyImage(image.attr('src'), size);
Expand Down Expand Up @@ -330,8 +328,6 @@ describe('SSG pictures with subpath - build', function () {
const image = $(`${id} img`);

expect(image.attr('src')).to.match(regex);
expect(image.attr('width')).to.equal(size.width.toString());
expect(image.attr('height')).to.equal(size.height.toString());
expect(image.attr('alt')).to.equal(alt);

verifyImage(image.attr('src').replace('/docs', ''), size);
Expand Down

0 comments on commit 944d24e

Please sign in to comment.