From d73c04a9e58c7d320cdb4f34604de76b30199778 Mon Sep 17 00:00:00 2001 From: Tony Sullivan Date: Tue, 19 Jul 2022 19:21:58 +0000 Subject: [PATCH] component should pass all unknown attributes to the element (#3961) * should pass all unrecognized props down to the element * chore: add changeset * Adding test coverage for custom attributes * chore: adding a README note for passing attributes to the picture's img * Revert " should pass all unrecognized props down to the element" This reverts commit ce3e33930f825ed91bc18c38caa205713212c1b9. * Picture should pass alt text to the img --- .changeset/chatty-bikes-sin.md | 5 +++++ packages/integrations/image/README.md | 6 +++--- .../image/components/Picture.astro | 10 ++++++---- .../basic-picture/src/pages/index.astro | 6 +++--- .../image/test/picture-ssg.test.js | 18 ++++++++++++------ .../image/test/picture-ssr.test.js | 12 +++++++++--- 6 files changed, 38 insertions(+), 19 deletions(-) create mode 100644 .changeset/chatty-bikes-sin.md diff --git a/.changeset/chatty-bikes-sin.md b/.changeset/chatty-bikes-sin.md new file mode 100644 index 000000000..99d999bda --- /dev/null +++ b/.changeset/chatty-bikes-sin.md @@ -0,0 +1,5 @@ +--- +'@astrojs/image': patch +--- + +Updates the component to pass the `alt` attribute down to the element diff --git a/packages/integrations/image/README.md b/packages/integrations/image/README.md index ee9fdf3c9..fef238891 100644 --- a/packages/integrations/image/README.md +++ b/packages/integrations/image/README.md @@ -188,13 +188,13 @@ const imageUrl = 'https://www.google.com/images/branding/googlelogo/2x/googlelog --- // Local image with multiple sizes - + // Remote image (aspect ratio is required) - + // Inlined imports are supported - + ``` diff --git a/packages/integrations/image/components/Picture.astro b/packages/integrations/image/components/Picture.astro index fb1f1e2bd..bff6aad89 100644 --- a/packages/integrations/image/components/Picture.astro +++ b/packages/integrations/image/components/Picture.astro @@ -4,15 +4,17 @@ import loader from 'virtual:image-loader'; import { getPicture } from '../src/get-picture.js'; import type { ImageAttributes, ImageMetadata, OutputFormat, PictureAttributes, TransformOptions } from '../src/types.js'; -export interface LocalImageProps extends Omit, Omit, Omit { +export interface LocalImageProps extends Omit, Omit, Pick { src: ImageMetadata | Promise<{ default: ImageMetadata }>; + alt?: string; sizes: HTMLImageElement['sizes']; widths: number[]; formats?: OutputFormat[]; } -export interface RemoteImageProps extends Omit, TransformOptions, Omit { +export interface RemoteImageProps extends Omit, TransformOptions, Pick { src: string; + alt?: string; sizes: HTMLImageElement['sizes']; widths: number[]; aspectRatio: TransformOptions['aspectRatio']; @@ -21,7 +23,7 @@ export interface RemoteImageProps extends Omit {sources.map(attrs => ( ))} - +