diff --git a/e2e/scratchpad-table-targets.spec.ts b/e2e/scratchpad-table-targets.spec.ts new file mode 100644 index 00000000..5b066db7 --- /dev/null +++ b/e2e/scratchpad-table-targets.spec.ts @@ -0,0 +1,103 @@ +import AxeBuilder from "@axe-core/playwright"; +import { expect, test } from "./local-test"; +import { outlineOf } from "./scratchpad-editor"; + +for (const [width, height, hasTouch] of [ + [1042, 662, false], + [1280, 800, false], + [390, 844, false], + [390, 844, true], +] as const) { + test.describe(`${width}×${height} ${hasTouch ? "coarse" : "fine"}`, () => { + test.use({ + viewport: { width, height }, + hasTouch, + reducedMotion: "reduce", + }); + test("Scratchpad checkbox clears inactive and active table controls", async ({ + page, + }) => { + await page.goto("scratchpad/?demo=60"); + const current = page.locator(".scratchpad-current-document"); + const editor = outlineOf(current); + const checkbox = current.getByRole("checkbox").first(); + await expect(checkbox).toBeVisible(); + const controls = current.locator(".cm-lp-table-controls > button"); + await expect(controls).toHaveCount(4); + expect( + await controls.evaluateAll((buttons) => + buttons.map((button) => button.getAttribute("title")), + ), + ).toEqual(["Column options", "Row options", "Add row", "Add column"]); + const measure = () => + checkbox.evaluate((box) => { + const rect = box.getBoundingClientRect(); + const overlaps = Array.from( + box + .closest(".cm-editor")! + .querySelectorAll(".cm-lp-table-controls > button"), + ) + .filter((el) => { + const other = el.getBoundingClientRect(); + return ( + Math.min(rect.right, other.right) > + Math.max(rect.left, other.left) && + Math.min(rect.bottom, other.bottom) > + Math.max(rect.top, other.top) + ); + }) + .map((el) => el.getAttribute("title")); + return { + x: rect.x, + y: rect.y, + width: rect.width, + height: rect.height, + overlaps, + }; + }); + const inactive = await measure(); + await test.info().attach("inactive geometry", { + body: JSON.stringify(inactive), + contentType: "application/json", + }); + expect + .soft(inactive, JSON.stringify(inactive)) + .toMatchObject({ width: 44, height: 44, overlaps: [] }); + await editor.fill( + "- [ ] Draft\n\n| Item | Value |\n| --- | --- |\n| One | Two |\n\n", + ); + await editor.getByText("One", { exact: true }).click(); + await expect( + current.locator(".cm-lp-table-controls-visible"), + ).toHaveCount(1); + for (const button of await controls.all()) { + await expect(button).toBeVisible(); + } + const active = await measure(); + await test.info().attach("active geometry", { + body: JSON.stringify(active), + contentType: "application/json", + }); + expect(active).toMatchObject({ width: 44, height: 44, overlaps: [] }); + expect( + await page.evaluate( + () => document.documentElement.scrollWidth - innerWidth, + ), + ).toBeLessThanOrEqual(0); + for (const colorScheme of ["light", "dark"] as const) { + await page.emulateMedia({ colorScheme }); + await expect(page.locator("html")).toHaveCSS( + "color-scheme", + colorScheme, + ); + expect( + ( + await new AxeBuilder({ page }) + .withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"]) + .analyze() + ).violations, + ).toEqual([]); + } + }); + }); +} diff --git a/src/styles/16-scratchpad-live-preview.css b/src/styles/16-scratchpad-live-preview.css index cb0c8618..1cb34a7e 100644 --- a/src/styles/16-scratchpad-live-preview.css +++ b/src/styles/16-scratchpad-live-preview.css @@ -48,24 +48,32 @@ position: relative; display: inline-block; box-sizing: border-box; - width: 17px; - height: 17px; + width: 44px; + height: 44px; margin: 0; padding: 0; - vertical-align: -3px; + vertical-align: middle; color: var(--paper); background: transparent; - border: 1.75px solid var(--ink-muted); - border-radius: 5px; + border: 0; cursor: pointer; + border-radius: 0; appearance: none; } -.markdown-source-editor .cm-lp-task:hover { +.markdown-source-editor .cm-lp-task::before { + position: absolute; + inset: 12px; + content: ""; + border: 1.75px solid var(--ink-muted); + border-radius: 5px; +} + +.markdown-source-editor .cm-lp-task:hover::before { border-color: var(--accent); } -.markdown-source-editor .cm-lp-task[aria-checked="true"] { +.markdown-source-editor .cm-lp-task[aria-checked="true"]::before { background: var(--accent); border-color: var(--accent); } @@ -137,37 +145,13 @@ color: var(--color-danger); } -@media (pointer: coarse), (max-width: 560px) { - /* Give the button its own column. Only the centred 20px box is painted. */ - .markdown-source-editor .cm-lp-task { - width: 44px; - height: 44px; - vertical-align: middle; - border: 0; - border-radius: 0; - background: transparent; - } - - .markdown-source-editor .cm-lp-task::before { - position: absolute; - inset: 12px; - content: ""; - border: 1.75px solid var(--ink-muted); - border-radius: 5px; - } - - .markdown-source-editor .cm-lp-task[aria-checked="true"] { - background: transparent; - } - - .markdown-source-editor .cm-lp-task[aria-checked="true"]::before { - background: var(--accent); - border-color: var(--accent); - } -} - @media (pointer: coarse) { .cm-lp-table-menu .mdbase-menu-item { min-height: 44px; } } + +/* The editor positions these buttons only while a table is active. */ +.scratchpad-note-text .cm-lp-table-controls:not(.cm-lp-table-controls-visible) { + display: none; +} diff --git a/src/styles/17-scratchpad-note.css b/src/styles/17-scratchpad-note.css index 739d627d..ed3a5686 100644 --- a/src/styles/17-scratchpad-note.css +++ b/src/styles/17-scratchpad-note.css @@ -18,7 +18,8 @@ } .scratchpad-note-text { - --scratch-line-pad: 3px; + --scratch-line-pad: 2px; + --scratch-marker-width: 44px; } .scratchpad-note-text .cm-line { @@ -100,6 +101,7 @@ } .scratchpad-note-text .cm-scratch-item { + min-height: 48px; --lp-list-indent: calc( var(--scratch-depth, 0) * var(--scratch-step) + var(--scratch-marker-width, var(--scratch-step)) @@ -323,17 +325,6 @@ } } -@media (pointer: coarse), (max-width: 560px) { - .scratchpad-note-text { - --scratch-line-pad: 2px; - --scratch-marker-width: 44px; - } - - .scratchpad-note-text .cm-scratch-item { - min-height: 48px; - } -} - @media (pointer: coarse) { .scratchpad-note-text .cm-gutters, .scratchpad-note-text .cm-scratch-fold-gutter,