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
50 changes: 50 additions & 0 deletions web/e2e/article-editor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { expect, test } from "@playwright/test";

import { loginAsAdmin } from "./helpers";

test.beforeEach(async ({ page }) => {
await loginAsAdmin(page);
await page.goto("/article/editor");
});

test("toggles the article summary with Enter and Space", async ({ page }) => {
const summary = page.getByRole("button", { name: /^(Summary|文章摘要)$/ });
const content = page.getByPlaceholder(/Enter article summary|请输入文章摘要/);

await expect(summary).toHaveAttribute("aria-expanded", "true");
await summary.press("Enter");
await expect(summary).toHaveAttribute("aria-expanded", "false");
await expect(summary).toBeFocused();
await expect(content).toBeHidden();

await summary.press("Space");
await expect(summary).toHaveAttribute("aria-expanded", "true");
await expect(content).toBeVisible();
});

test("moves between editor toolbar buttons and activates them with the keyboard", async ({
page,
}) => {
const split = page.getByRole("button", { name: /^(Split|分屏)$/ });
const toolbar = page.locator("header").filter({ has: split });
const edit = toolbar.getByRole("button", { name: /^(Edit|编辑)$/ });
const preview = toolbar.getByRole("button", { name: /^(Preview|预览)$/ });
const outline = toolbar.getByRole("button", { name: /^(Outline|大纲)$/ });

await expect(split).toHaveAttribute("aria-pressed", "true");
await edit.press("Enter");
await expect(edit).toHaveAttribute("aria-pressed", "true");
await page.keyboard.press("Tab");
await expect(split).toBeFocused();
await page.keyboard.press("Tab");
await expect(preview).toBeFocused();
await page.keyboard.press("Space");
await expect(preview).toHaveAttribute("aria-pressed", "true");

await outline.press("Enter");
await expect(outline).toHaveAttribute("aria-pressed", "false");
await outline.press("Space");
await expect(outline).toHaveAttribute("aria-pressed", "true");
await page.keyboard.press("Tab");
await expect(toolbar.getByRole("button", { name: /^(Fullscreen|全屏)$/ })).toBeFocused();
});
9 changes: 7 additions & 2 deletions web/src/modules/article/components/EditorMetaPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ export function EditorMetaPanel({ title, defaultOpen = true, children }: EditorM

return (
<section className={styles.panel}>
<header className={styles.header} onClick={() => setOpen((v) => !v)}>
<button
type="button"
className={styles.header}
aria-expanded={open}
onClick={() => setOpen((v) => !v)}
>
<span className={styles.title}>{title}</span>
<span className={styles.toggle} aria-hidden>
{open ? <ChevronUp size={16} /> : <ChevronDown size={16} />}
</span>
</header>
</button>
{open ? <div className={styles.body}>{children}</div> : null}
</section>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
padding: 10px 12px;
background: var(--editor-surface-muted);
border: 0;
border-bottom: 1px solid var(--editor-border-secondary);
font: inherit;
text-align: start;
cursor: pointer;
user-select: none;
}

.header:focus-visible {
outline: 2px solid var(--editor-accent);
outline-offset: -2px;
}

.title {
font-size: 13px;
font-weight: 600;
Expand Down
8 changes: 8 additions & 0 deletions web/src/shared/components/Editor/editor.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@

.toolbarAction {
padding: 0 10px;
border: 0;
background: transparent;
font-family: inherit;
font-size: 12px;
line-height: 28px;
white-space: nowrap;
Expand All @@ -98,6 +101,11 @@
background: var(--editor-hover-bg);
}

.toolbarAction:focus-visible {
outline: 2px solid var(--editor-accent);
outline-offset: -2px;
}

.toolbarActionActive {
background: var(--editor-active-bg);
font-weight: 600;
Expand Down
33 changes: 23 additions & 10 deletions web/src/shared/components/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ export function MarkdownEditor({
</span>
</div>
<div className={styles.toolbarRight}>
<span
<button
type="button"
aria-pressed={mode === "edit" && !split}
className={cls(
styles.toolbarAction,
mode === "edit" && !split && styles.toolbarActionActive,
Expand All @@ -235,8 +237,10 @@ export function MarkdownEditor({
>
<PanelLeft size={14} style={{ verticalAlign: -2, marginRight: 4 }} />
{t("editor.modeEdit")}
</span>
<span
</button>
<button
type="button"
aria-pressed={split}
className={cls(styles.toolbarAction, split && styles.toolbarActionActive)}
onClick={() => {
setSplit(true);
Expand All @@ -245,8 +249,10 @@ export function MarkdownEditor({
>
<Columns2 size={14} style={{ verticalAlign: -2, marginRight: 4 }} />
{t("editor.modeSplit")}
</span>
<span
</button>
<button
type="button"
aria-pressed={mode === "preview" && !split}
className={cls(
styles.toolbarAction,
mode === "preview" && !split && styles.toolbarActionActive,
Expand All @@ -258,15 +264,22 @@ export function MarkdownEditor({
>
<Eye size={14} style={{ verticalAlign: -2, marginRight: 4 }} />
{t("editor.modePreview")}
</span>
</button>
<Divider type="vertical" />
<span className={styles.toolbarAction} onClick={() => toggleTocVisible()}>
<button
type="button"
className={styles.toolbarAction}
aria-pressed={tocVisible}
onClick={() => toggleTocVisible()}
>
<ListTree size={14} style={{ verticalAlign: -2, marginRight: 4 }} />
{t("editor.toc")}
</span>
</button>
<Divider type="vertical" />
<Tooltip title={fullscreen ? t("editor.exitFullscreen") : t("editor.fullscreen")}>
<span
<button
type="button"
aria-label={fullscreen ? t("editor.exitFullscreen") : t("editor.fullscreen")}
className={cls(styles.toolbarAction, fullscreen && styles.toolbarActionActive)}
onClick={() => void toggleFullscreen()}
>
Expand All @@ -275,7 +288,7 @@ export function MarkdownEditor({
) : (
<Maximize2 size={14} style={{ verticalAlign: -2 }} />
)}
</span>
</button>
</Tooltip>
</div>
</header>
Expand Down