Update Picture.astro so it no longer passes height and width attributes (#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 <tony.f.sullivan@outlook.com>
This commit is contained in:
parent
a5df3f313e
commit
944d24e9ee
3 changed files with 8 additions and 4 deletions
5
.changeset/selfish-files-smoke.md
Normal file
5
.changeset/selfish-files-smoke.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/image': patch
|
||||
---
|
||||
|
||||
Do not pass width and height to the img element when wrapped in a picture element
|
|
@ -60,6 +60,9 @@ const { image, sources } = await getPicture({
|
|||
background,
|
||||
position,
|
||||
});
|
||||
|
||||
delete image.width;
|
||||
delete image.height;
|
||||
---
|
||||
|
||||
<picture {...attrs}>
|
||||
|
|
|
@ -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);
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue