Show the current choice, keyboard focus, and states apart
Phase 5-5. - The current radio row shows a check mark in the icon column and no fill (UI-051, replaces the radio rule of UI-003). The list of all tabs names pinned tabs in text. - Keyboard focus adds a 2-pixel ring inside menu rows. The global focus ring is 2 pixels with a 1-pixel offset. - Active toggles get the accent color, the selection fill, and a 2-pixel accent bar. Hover gets only a neutral fill. Enabled icon buttons use --rs-text. - Disabled controls use --rs-text-dim at full opacity, not opacity. - The file tree has one Tab stop. Up and Down move, Shift extends the selection, Right opens or enters a folder, Left closes it or goes to its parent, Home and End go to the ends, and typed letters find a row. - The three workbench splitters take focus. The arrow keys move them by 16 pixels, and Home and End go to their limits. - Help names Esc, then Tab, to leave the text. - 5 new catalog rows in French, Japanese, and Simplified Chinese. - Docs: UI-051, ui-design.md, and the user guide. Tests: the new layout/keyboardFocus. backgroundImages now expects the check mark on the current radio row.
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
// Keyboard and focus: radio check marks, menu focus rings, hover against active, readable disabled controls, the file tree keys, and splitters.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("layout/keyboardFocus", async ({ page }) => {
|
||||
const output = await outputDir("layout/keyboardFocus");
|
||||
await mockTauri(page, {
|
||||
commands: test => ({
|
||||
...test.workspace({
|
||||
root: "C:\\keyboard",
|
||||
files: {
|
||||
"alpha.md": "# Alpha\n",
|
||||
"beta.md": "# Beta\n",
|
||||
"notes/first.md": "# First\n",
|
||||
"notes/second.md": "# Second\n",
|
||||
"notes/deep/third.md": "# Third\n",
|
||||
"zeta.txt": "Zeta\n",
|
||||
},
|
||||
}),
|
||||
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
|
||||
"plugin:window|is_maximized": () => false,
|
||||
}),
|
||||
});
|
||||
await page.setViewportSize({ width: 1280, height: 760 });
|
||||
await page.goto(smokeUrl);
|
||||
const tree = page.getByRole("tree", { name: "Workspace files" });
|
||||
const row = rel => page.locator(`[data-tree-rel="${rel}"]`);
|
||||
const focused = () => page.evaluate(() => document.activeElement?.getAttribute("data-tree-rel") ?? document.activeElement?.getAttribute("aria-label"));
|
||||
await row("alpha.md").waitFor();
|
||||
|
||||
// The tree has one Tab stop. Arrow keys move, Right opens or enters a folder, Left closes it or goes up.
|
||||
assert.equal(await tree.locator('[role="treeitem"][tabindex="0"]').count(), 1);
|
||||
await row("alpha.md").click();
|
||||
await page.getByRole("tab", { name: "alpha.md", exact: true, selected: true }).waitFor();
|
||||
await row("alpha.md").focus();
|
||||
await page.keyboard.press("ArrowDown");
|
||||
assert.equal(await focused(), "beta.md");
|
||||
assert.equal(await row("beta.md").getAttribute("aria-selected"), "true");
|
||||
// Folders come first: notes, alpha.md, beta.md, zeta.txt.
|
||||
await page.keyboard.press("ArrowDown");
|
||||
assert.equal(await focused(), "zeta.txt");
|
||||
await page.keyboard.press("Home");
|
||||
assert.equal(await focused(), "notes");
|
||||
await page.keyboard.press("ArrowRight");
|
||||
await row("notes/first.md").waitFor();
|
||||
assert.equal(await row("notes").getAttribute("aria-expanded"), "true");
|
||||
await page.keyboard.press("ArrowRight");
|
||||
assert.equal(await focused(), "notes/deep");
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
assert.equal(await focused(), "notes");
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
assert.equal(await row("notes").getAttribute("aria-expanded"), "false");
|
||||
await page.keyboard.press("End");
|
||||
assert.equal(await focused(), "zeta.txt");
|
||||
await page.keyboard.press("Home");
|
||||
assert.equal(await focused(), "notes");
|
||||
await page.keyboard.press("z");
|
||||
assert.equal(await focused(), "zeta.txt");
|
||||
await page.keyboard.press("Shift+ArrowUp");
|
||||
assert.equal(await tree.locator('[aria-selected="true"]').count(), 2);
|
||||
assert.equal(await tree.locator('[role="treeitem"][tabindex="0"]').count(), 1);
|
||||
// Tab leaves the tree at once.
|
||||
await page.keyboard.press("Tab");
|
||||
assert.notEqual(await page.evaluate(() => !!document.activeElement?.closest('[role="tree"]')), true);
|
||||
await page.keyboard.press("Shift+Tab");
|
||||
assert.equal(await page.evaluate(() => !!document.activeElement?.closest('[role="tree"]')), true);
|
||||
|
||||
// A splitter takes focus. The arrow keys move it by 16 pixels, and Home and End go to its limits.
|
||||
const splitter = page.getByRole("separator", { name: "Resize the side pane", exact: true });
|
||||
const width = () => page.locator("aside.left").evaluate(node => Math.round(node.getBoundingClientRect().width));
|
||||
const before = await width();
|
||||
await splitter.focus();
|
||||
await page.keyboard.press("ArrowRight");
|
||||
assert.equal(await width(), before + 16);
|
||||
assert.equal(await splitter.getAttribute("aria-valuenow"), String(before + 16));
|
||||
await page.keyboard.press("Home");
|
||||
assert.equal(await width(), 160);
|
||||
await page.keyboard.press("End");
|
||||
assert.equal(await width(), 480);
|
||||
assert.equal(await splitter.evaluate(node => getComputedStyle(node).outlineWidth), "2px");
|
||||
const outline = page.getByRole("separator", { name: "Resize the outline", exact: true });
|
||||
await outline.focus();
|
||||
const right = () => page.locator("aside.right").evaluate(node => Math.round(node.getBoundingClientRect().width));
|
||||
const rightBefore = await right();
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
assert.equal(await right(), rightBefore + 16);
|
||||
await splitter.focus();
|
||||
await page.keyboard.press("Home");
|
||||
|
||||
for (const theme of ["dark", "light"]) {
|
||||
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); window.dispatchEvent(new Event("focus")); }, theme);
|
||||
await page.waitForFunction(mode => document.documentElement.dataset.theme === mode, theme);
|
||||
|
||||
// An active toggle differs from a hovered button. A disabled button keeps full opacity and dim text.
|
||||
const files = page.getByRole("button", { name: "Files", exact: true });
|
||||
const search = page.getByRole("button", { name: "Search", exact: true });
|
||||
await search.hover();
|
||||
const look = locator => locator.evaluate(node => { const style = getComputedStyle(node); return { fill: style.backgroundColor, color: style.color, bar: style.boxShadow }; });
|
||||
const [hovered, active] = [await look(search), await look(files)];
|
||||
assert.equal(hovered.bar, "none");
|
||||
assert.match(active.bar, /inset/);
|
||||
assert.notEqual(hovered.color, active.color);
|
||||
const save = page.getByRole("button", { name: "Save", exact: true });
|
||||
assert.equal(await save.isDisabled(), true);
|
||||
assert.equal(await save.evaluate(node => getComputedStyle(node).opacity), "1");
|
||||
const dim = await page.evaluate(() => { const probe = document.createElement("span"); probe.style.color = "var(--rs-text-dim)"; document.body.append(probe); const color = getComputedStyle(probe).color; probe.remove(); return color; });
|
||||
assert.equal(await save.evaluate(node => getComputedStyle(node).color), dim);
|
||||
await page.locator("header.header").screenshot({ path: `${output}/header-states-${theme}.png` });
|
||||
|
||||
// The current radio row shows a check mark and no fill. Keyboard focus adds a ring that hover does not have.
|
||||
await page.getByRole("tab", { name: "alpha.md", exact: true }).click({ button: "right" });
|
||||
await page.getByRole("menuitem", { name: "View", exact: true }).click();
|
||||
const write = page.getByRole("menuitemradio", { name: "Write", exact: true });
|
||||
const source = page.getByRole("menuitemradio", { name: "Source", exact: true });
|
||||
assert.equal(await write.getAttribute("aria-checked"), "true");
|
||||
assert.equal(await write.locator("svg").count(), 1);
|
||||
assert.equal(await source.locator("svg").count(), 0);
|
||||
await source.hover();
|
||||
assert.equal(await source.evaluate(node => getComputedStyle(node).outlineStyle), "none");
|
||||
await write.focus();
|
||||
await page.keyboard.press("ArrowDown");
|
||||
const keyed = page.locator('[role="menu"] button:focus-visible');
|
||||
assert.equal(await keyed.getAttribute("aria-checked"), "false");
|
||||
assert.equal(await keyed.evaluate(node => getComputedStyle(node).outlineWidth), "2px");
|
||||
// With focus and the pointer on other rows, the checked row has no fill.
|
||||
await page.mouse.move(0, 700);
|
||||
assert.equal(await write.evaluate(node => getComputedStyle(node).backgroundColor), "rgba(0, 0, 0, 0)");
|
||||
await page.screenshot({ path: `${output}/menu-check-${theme}.png` });
|
||||
await page.keyboard.press("Escape");
|
||||
await page.keyboard.press("Escape");
|
||||
await page.keyboard.press("Escape");
|
||||
|
||||
// Disabled menu rows keep full opacity and dim text.
|
||||
await page.getByRole("tab", { name: "alpha.md", exact: true }).click({ button: "right" });
|
||||
const disabled = page.getByRole("menuitem", { name: "Close tabs after", exact: true });
|
||||
assert.equal(await disabled.isDisabled(), true);
|
||||
assert.equal(await disabled.evaluate(node => getComputedStyle(node).opacity), "1");
|
||||
assert.equal(await disabled.evaluate(node => getComputedStyle(node).color), dim);
|
||||
await page.keyboard.press("Escape");
|
||||
}
|
||||
|
||||
// Help names the key that leaves the text before Tab moves on.
|
||||
await page.keyboard.press("F1");
|
||||
await page.getByRole("dialog", { name: "Help and about" }).getByText("Leave the text, then press Tab", { exact: true }).waitFor();
|
||||
await page.getByRole("button", { name: "Close help", exact: true }).click();
|
||||
assert.deepEqual(page.errors, []);
|
||||
console.log("PASS: one tree Tab stop, tree keys, type-ahead, range selection, keyboard splitters, radio check marks, menu focus ring, hover against active, readable disabled controls, Help, both themes.");
|
||||
});
|
||||
Reference in New Issue
Block a user