Skip to content

Commit 179706d

Browse files
committed
Preserve MImageBody legacy class names
1 parent 7994966 commit 179706d

3 files changed

Lines changed: 38 additions & 5 deletions

File tree

packages/shared-components/src/room/timeline/event-tile/body/MImageBodyView/ImageBodyView.module.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
text-decoration: none;
2020
}
2121

22-
.thumbnailContainer {
22+
.thumbnailContainer,
23+
:global(.mx_MImageBody_thumbnail_container) {
2324
position: relative;
2425
overflow: hidden;
2526
contain: paint;
@@ -57,7 +58,8 @@
5758
max-height: 100%;
5859
}
5960

60-
.image {
61+
.image,
62+
:global(.mx_MImageBody_thumbnail) {
6163
display: block;
6264
width: 100%;
6365
height: 100%;

packages/shared-components/src/room/timeline/event-tile/body/MImageBodyView/ImageBodyView.test.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,37 @@ describe("ImageBodyView", () => {
112112
expect(onLinkClick).toHaveBeenCalledTimes(1);
113113
});
114114

115+
it("preserves supplied legacy class names without appending module classes", () => {
116+
const vm = new TestImageBodyViewModel({
117+
state: ImageBodyViewState.READY,
118+
alt: "Legacy class image",
119+
src: "https://example.org/full.png",
120+
thumbnailSrc: "https://example.org/thumb.png",
121+
maxWidth: 320,
122+
maxHeight: 240,
123+
aspectRatio: "4 / 3",
124+
});
125+
126+
const { container } = render(
127+
<ImageBodyView
128+
vm={vm}
129+
className="mx_MImageBody"
130+
containerClassName="mx_MImageBody_thumbnail_container"
131+
imageClassName="mx_MImageBody_thumbnail"
132+
/>,
133+
);
134+
135+
expect(container.querySelector(".mx_MImageBody")).toHaveAttribute("class", "mx_MImageBody");
136+
expect(container.querySelector(".mx_MImageBody_thumbnail_container")).toHaveAttribute(
137+
"class",
138+
"mx_MImageBody_thumbnail_container",
139+
);
140+
expect(screen.getByRole("img", { name: "Legacy class image" })).toHaveAttribute(
141+
"class",
142+
"mx_MImageBody_thumbnail",
143+
);
144+
});
145+
115146
it("swaps to the full source on hover for animated previews", async () => {
116147
const user = userEvent.setup();
117148
const vm = new TestImageBodyViewModel({

packages/shared-components/src/room/timeline/event-tile/body/MImageBodyView/ImageBodyView.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ export function ImageBodyView({
249249
const [focus, setFocus] = useState(false);
250250
const hoverOrFocus = hover || focus;
251251

252-
const rootClassName = classNames(className, styles.root);
253-
const resolvedContainerClassName = classNames(containerClassName, styles.thumbnailContainer);
254-
const resolvedImageClassName = classNames(imageClassName, styles.image);
252+
const rootClassName = className ?? styles.root;
253+
const resolvedContainerClassName = containerClassName ?? styles.thumbnailContainer;
254+
const resolvedImageClassName = imageClassName ?? styles.image;
255255

256256
if (state === ImageBodyViewState.ERROR) {
257257
return (

0 commit comments

Comments
 (0)