diff --git a/src/components/image/image.e2e.ts b/src/components/image/image.e2e.ts index fa31448834..fd14b825cc 100644 --- a/src/components/image/image.e2e.ts +++ b/src/components/image/image.e2e.ts @@ -41,7 +41,7 @@ describe(`sbb-image with ${fixture.name}`, () => { - + diff --git a/src/components/image/image.scss b/src/components/image/image.scss index 0189465a37..146b21bd2b 100644 --- a/src/components/image/image.scss +++ b/src/components/image/image.scss @@ -54,7 +54,7 @@ // aspect ratios 'free', '1-1', '1-2', '2-1', '2-3', '3-2', '3-4', '4-3', '4-5', '5-4', '9-16', '16-9' .image__figure--ratio-free .image__wrapper { - aspect-ratio: auto; + aspect-ratio: var(--sbb-image-aspect-ratio, auto); } .image__figure--ratio-1-1 .image__wrapper { diff --git a/src/components/image/image.ts b/src/components/image/image.ts index c7515ca941..f5a95c6ad4 100644 --- a/src/components/image/image.ts +++ b/src/components/image/image.ts @@ -59,6 +59,14 @@ const breakpointMap: Record = { /** * It displays an image. + * + * @cssprop [--sbb-image-aspect-ratio=auto] - When the aspectRatio property + * on the component is set to 'free', the CSS declaration of the aspect + * ratio is set to var(--sbb-image-aspect-ratio, auto). Since CSS + * variables find their way into the shadow DOM, we can use the + * --sbb-image-aspect-ratio variable to override the aspect ratio at will. + * This way we can have, for example, an image component with an aspect + * ratio of 4/3 in smaller viewports and 16/9 in larger viewports. */ @customElement('sbb-image') export class SbbImageElement extends LitElement { @@ -457,6 +465,12 @@ export class SbbImageElement extends LitElement { const pictureSizeConfigs = this._preparePictureSizeConfigs(); + /** + * The alt attribute should always be present for the img element. + * If it has an empty string as its value, it is simply ignored + * by assistive technologies. If we leave it out completely, + * they might try to interpret the img element. + */ return html`