Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/comment-form-rtl-overflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"emdash": patch
---

Fixes `<CommentForm>` making right-to-left pages (`<html dir="rtl">`) about 10,000 pixels wider, with a horizontal scrollbar. This happened on every such page in Firefox, and in Chrome and Safari when the form or an element around it is positioned, for example with `position: relative`. On right-to-left pages, `<Comments>` now also indents threaded replies from the right, and the separator before a signed-in commenter's email in `<CommentForm>` no longer touches the email.
24 changes: 23 additions & 1 deletion e2e/tests/public-page-styles.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { Page } from "@playwright/test";

import { test, expect } from "../fixtures";

test("a component's scoped styles apply on a public content page", async ({ page }) => {
async function openPostWithCommentForm(page: Page) {
const field = page.locator(".ec-comment-form-field").first();

// The workerd dev runner's Vite dep optimizer can transiently 500 a cold
Expand All @@ -12,5 +14,25 @@ test("a component's scoped styles apply on a public content page", async ({ page
await page.waitForTimeout(1000);
}

return field;
}

test("a component's scoped styles apply on a public content page", async ({ page }) => {
const field = await openPostWithCommentForm(page);

await expect(field).toHaveCSS("display", "flex");
});

test("the comment form doesn't widen a right-to-left page", async ({ page }) => {
await expect(await openPostWithCommentForm(page)).toBeVisible();

const width = await page.locator("html").evaluate((html) => {
html.dir = "rtl";
// Chromium leaves off-page absolutely positioned content out of the
// scroll width unless that content has a positioned ancestor.
document.body.style.position = "relative";
return { scroll: html.scrollWidth, client: html.clientWidth };
});

expect(width.scroll).toBe(width.client);
});
4 changes: 2 additions & 2 deletions packages/core/src/components/CommentForm.astro
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const endpoint = `/_emdash/api/comments/${encodeURIComponent(collection)}/${enco
{/* Honeypot — hidden from humans, filled by bots */}
<div
aria-hidden="true"
style="position:absolute;left:-9999px;top:-9999px;"
style="position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap;"
>
<label>
Don't fill this out
Expand Down Expand Up @@ -323,7 +323,7 @@ const endpoint = `/_emdash/api/comments/${encodeURIComponent(collection)}/${enco

.ec-comment-user-email::before {
content: "·";
margin-right: 0.5rem;
margin-inline-end: 0.5rem;
}

.ec-comment-form-submit {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/Comments.astro
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ const REACTION_SCRIPT = `

.ec-comment-replies {
margin-top: var(--ec-comment-gap);
padding-left: var(--ec-comment-indent);
padding-inline-start: var(--ec-comment-indent);
}

.ec-comment-replies > li + li {
Expand Down
Loading