From ed2dfdae5bea93746be883bc528c1fb6407af6eb Mon Sep 17 00:00:00 2001 From: Emmanuel Chucks <31349069+emmanuelchucks@users.noreply.github.com> Date: Thu, 20 Oct 2022 19:42:36 +0000 Subject: [PATCH] fix: updates to pass HTML attributes down to the element (#5038) * fix: also pass attrs to underlying img `class` for direct img styling, `width` & `height` to prevent layout shift, etc need to be passed to the underlying img tag to work. * remove redundant attr from picture tag * revert to previous commit - seemed to break some tests - can't deal with fixing that right now, maybe later * only passing attributes to the img * adding a note to the README * chore: add changeset Co-authored-by: Tony Sullivan --- .changeset/wicked-laws-heal.md | 11 ++++++++ packages/integrations/image/README.md | 4 +++ .../image/components/Picture.astro | 4 +-- .../basic-picture/src/pages/index.astro | 2 +- .../image/test/picture-ssg.test.js | 28 +++++++++++-------- .../image/test/picture-ssr-build.test.js | 12 ++++---- .../image/test/picture-ssr-dev.test.js | 12 ++++---- 7 files changed, 46 insertions(+), 27 deletions(-) create mode 100644 .changeset/wicked-laws-heal.md diff --git a/.changeset/wicked-laws-heal.md b/.changeset/wicked-laws-heal.md new file mode 100644 index 000000000..bcaac6132 --- /dev/null +++ b/.changeset/wicked-laws-heal.md @@ -0,0 +1,11 @@ +--- +'@astrojs/image': minor +--- + +HTML attributes included on the `` component are now passed down to the underlying `` element. + +**Why?** + +- when styling a `` the `class` and `style` attributes belong on the `` itself +- `` elements [should not](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture#attributes) actually provide any `aria-` attributes +- `width` and `height` can be added to the `` to help prevent layout shift diff --git a/packages/integrations/image/README.md b/packages/integrations/image/README.md index e57331124..70c6bbcd0 100644 --- a/packages/integrations/image/README.md +++ b/packages/integrations/image/README.md @@ -260,6 +260,10 @@ Position of the crop when fit is `cover` or `contain`. ### `` +The built-in `` component is used to create an optimized `` for both remote images hosted on other domains as well as local images imported from your project's `src` directory. + +In addition to the component-specific properties, any valid HTML attribute for the `` included in the `` component will be included in the built ``. + #### src

diff --git a/packages/integrations/image/components/Picture.astro b/packages/integrations/image/components/Picture.astro index e86ccc65d..7cd71d600 100644 --- a/packages/integrations/image/components/Picture.astro +++ b/packages/integrations/image/components/Picture.astro @@ -65,9 +65,9 @@ delete image.width; delete image.height; --- - + {sources.map((attrs) => )} - +