diff --git a/web/e2e/article-editor.spec.ts b/web/e2e/article-editor.spec.ts new file mode 100644 index 00000000..861cecaa --- /dev/null +++ b/web/e2e/article-editor.spec.ts @@ -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(); +}); diff --git a/web/src/modules/article/components/EditorMetaPanel.tsx b/web/src/modules/article/components/EditorMetaPanel.tsx index 2c68f522..a0641ab4 100644 --- a/web/src/modules/article/components/EditorMetaPanel.tsx +++ b/web/src/modules/article/components/EditorMetaPanel.tsx @@ -14,12 +14,17 @@ export function EditorMetaPanel({ title, defaultOpen = true, children }: EditorM return (
-
setOpen((v) => !v)}> +
+ {open ?
{children}
: null}
); diff --git a/web/src/modules/article/components/editor-meta-panel.module.css b/web/src/modules/article/components/editor-meta-panel.module.css index b3092a17..ae43d6b9 100644 --- a/web/src/modules/article/components/editor-meta-panel.module.css +++ b/web/src/modules/article/components/editor-meta-panel.module.css @@ -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; diff --git a/web/src/shared/components/Editor/editor.module.css b/web/src/shared/components/Editor/editor.module.css index 6593a906..aca53471 100644 --- a/web/src/shared/components/Editor/editor.module.css +++ b/web/src/shared/components/Editor/editor.module.css @@ -85,6 +85,9 @@ .toolbarAction { padding: 0 10px; + border: 0; + background: transparent; + font-family: inherit; font-size: 12px; line-height: 28px; white-space: nowrap; @@ -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; diff --git a/web/src/shared/components/Editor/index.tsx b/web/src/shared/components/Editor/index.tsx index 90e34f4c..d24c4e7d 100644 --- a/web/src/shared/components/Editor/index.tsx +++ b/web/src/shared/components/Editor/index.tsx @@ -223,7 +223,9 @@ export function MarkdownEditor({
- {t("editor.modeEdit")} - - + - toggleTocVisible()}> + - void toggleFullscreen()} > @@ -275,7 +288,7 @@ export function MarkdownEditor({ ) : ( )} - +