From 31d8918d7e43bf386b639f0f9faec1b445802925 Mon Sep 17 00:00:00 2001 From: gjulivan Date: Mon, 16 Nov 2026 23:05:16 +0100 Subject: [PATCH] fix(image-web): apply height in viewport units ContentImage and BackgroundImage overwrote the height from constructStyleObject with getStyle(), which only handled pixels and percentage and returned "" for viewport, so a height in vh was dropped. Co-Authored-By: Claude Opus 5.5 --- .../pluggableWidgets/image-web/CHANGELOG.md | 2 ++ .../image-web/src/components/Image/ui.tsx | 2 ++ .../src/components/__tests__/Image.spec.tsx | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/packages/pluggableWidgets/image-web/CHANGELOG.md b/packages/pluggableWidgets/image-web/CHANGELOG.md index d9f88bd993..ea7e972f4d 100644 --- a/packages/pluggableWidgets/image-web/CHANGELOG.md +++ b/packages/pluggableWidgets/image-web/CHANGELOG.md @@ -10,6 +10,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - We fixed an issue where an image enlarged on click was shown smaller than the image on the page when its width was a percentage or a maximum height was set. The enlarged image now shows at its natural size, or at its size on the page when that is larger, scaled down to fit the screen. +- We fixed an issue where a height in viewport units was not applied to the image. + ## [1.6.1] - 2026-08-14 ### Fixed diff --git a/packages/pluggableWidgets/image-web/src/components/Image/ui.tsx b/packages/pluggableWidgets/image-web/src/components/Image/ui.tsx index 5868c11315..fac1f3276f 100644 --- a/packages/pluggableWidgets/image-web/src/components/Image/ui.tsx +++ b/packages/pluggableWidgets/image-web/src/components/Image/ui.tsx @@ -11,6 +11,8 @@ function getStyle(value: string | number, type: WidthUnitEnum | HeightUnitEnum): return value; } else if (type === "percentage") { return value + "%"; + } else if (type === "viewport") { + return value + "vh"; } return ""; diff --git a/packages/pluggableWidgets/image-web/src/components/__tests__/Image.spec.tsx b/packages/pluggableWidgets/image-web/src/components/__tests__/Image.spec.tsx index 6014a05705..66865cbd7a 100644 --- a/packages/pluggableWidgets/image-web/src/components/__tests__/Image.spec.tsx +++ b/packages/pluggableWidgets/image-web/src/components/__tests__/Image.spec.tsx @@ -91,6 +91,24 @@ describe("Image", () => { expect(image.asFragment()).toMatchSnapshot(); }); + it("applies a height in viewport units to the image", () => { + const { getByRole } = render(); + expect(getByRole("img")).toHaveStyle({ height: "30vh" }); + }); + + it("applies a height in viewport units to the background image", () => { + const { container } = render( + Image content} + /> + ); + expect(container.querySelector(".mx-image-background")).toHaveStyle({ height: "30vh" }); + }); + it("renders the structure with a glyph icon", () => { const image = render(); expect(image.asFragment()).toMatchSnapshot();