Skip to content

Commit 5563144

Browse files
committed
Fix comparison preview body alignment
1 parent d588470 commit 5563144

2 files changed

Lines changed: 54 additions & 3 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { expect, test } from "@playwright/test";
2+
import { waitForComparisonRouteReady } from "./comparison-page";
3+
import { pinComparisonTheme } from "./visual-diff";
4+
5+
test.describe("component page layout", () => {
6+
test("keeps rendered framework examples visible near the top of tall previews", async ({
7+
page,
8+
}) => {
9+
await pinComparisonTheme(page, "dark");
10+
await page.goto("/components/searchfield/");
11+
await waitForComparisonRouteReady(page);
12+
13+
const section = page.locator("#example").filter({
14+
has: page.locator("h2", { hasText: "Example" }),
15+
});
16+
const metrics = await section.locator(".s2-framework-panel").evaluateAll((panels) =>
17+
panels.map((panel) => {
18+
const fixture = panel.querySelector<HTMLElement>("[data-comparison-control-root]");
19+
20+
if (fixture == null) {
21+
throw new Error("Expected framework panel to contain a rendered fixture root.");
22+
}
23+
24+
const panelRect = panel.getBoundingClientRect();
25+
const fixtureRect = fixture.getBoundingClientRect();
26+
27+
return {
28+
framework: panel.getAttribute("data-framework") ?? "unknown",
29+
fixtureTop: Number(fixtureRect.top.toFixed(4)),
30+
topOffset: Number((fixtureRect.top - panelRect.top).toFixed(4)),
31+
viewportHeight: window.innerHeight,
32+
};
33+
}),
34+
);
35+
36+
expect(metrics).toHaveLength(2);
37+
38+
for (const metric of metrics) {
39+
expect(
40+
metric.fixtureTop,
41+
`${metric.framework} fixture should be in the initial viewport`,
42+
).toBeLessThan(metric.viewportHeight);
43+
expect(
44+
metric.topOffset,
45+
`${metric.framework} fixture should not be vertically centered below tall controls`,
46+
).toBeLessThanOrEqual(160);
47+
}
48+
});
49+
});

apps/comparison/src/styles/global.css

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,8 @@ html[data-theme="dark"] body.s2-docs {
753753
.s2-framework-panel > .comparison-island,
754754
.s2-framework-panel > .s2-empty-state {
755755
display: grid;
756-
place-items: center;
756+
align-items: start;
757+
justify-items: center;
757758
height: 100%;
758759
min-height: var(--s2-example-preview-min-height);
759760
padding: 44px 16px 26px;
@@ -780,8 +781,9 @@ html[data-theme="dark"] body.s2-docs {
780781
inline-size: max-content;
781782
max-inline-size: 100%;
782783
justify-self: center;
783-
align-content: center;
784-
place-items: center;
784+
align-content: start;
785+
align-items: start;
786+
justify-items: center;
785787
min-height: auto;
786788
}
787789

0 commit comments

Comments
 (0)