Public: anyone can read this; the crew can change it.

The forge toolbar can move to the other side of the screen, and each app remembers the side #14568

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

torque/forge:torque/14565-the-forge-toolbar-can-move-to-the-other → main 7 commits fork 1 thread · 1 unresolved

  • Merged. torque/14565-the-forge-toolbar-can-move-to-the-other was merged into main as 2d72ce3.

Review

Sign in to review this change.
3 files changed +89 −10
docs/features/forge-toolbar.md +10
@@ -51,6 +51,16 @@ preview), so you always know where you are and can get back to the forge.
5151 pill out; the app still works.
5252 - **Off:** `"toolbar": false` in `forge.json`.
5353
54 ## Moving the toolbar
55
56 The pill sits bottom-right until you move it. Three ways, all the same move:
57
58 - **The panel button:** "Move to the other side" in the open panel swaps left and right and keeps the height. It sits in the panel, so the pill itself does not change size; it is the last tab stop, after Close.
59 - **Arrow keys:** with the pill focused, Left and Right choose the side, Up and Down the top or bottom.
60 - **Drag:** drag the pill to a corner; it snaps to the nearest one.
61
62 Each move is announced to screen readers ("Moved to the top right"). The corner is remembered per app origin in the browser (`forge-pill-corner`), independent of dismissal; an unknown stored value falls back to bottom-right. `test/toolbar-swap.test.ts`.
63
5464 Tests: `test/toolbar-injection.test.ts`, `test/apps-toolbar.test.ts`, `test/note-context.test.ts`, `test/apps-feedback.test.ts`, `test/apps-toolbar-yours.test.ts`, `test/toolbar-serving.test.ts`, `test/toolbar-where.test.ts`, `test/toolbar-budget.test.ts`.
5565
5666 ## By keyboard and screen reader
src/apps/toolbar.ts +21 −10
@@ -5,10 +5,10 @@
55 * allows no foreign scripts simply leaves the pill out.
66 *
77 * The pill lives in a shadow root and is collapsed to a dot until pressed.
8 * It sits bottom-right until dragged or arrow-keyed to another corner; the
9 * corner is kept per app host in localStorage. It styles itself through the CSSOM
10 * (never a `style` attribute or a `<style>` element), which a strict
11 * `style-src` does not block.
8 * It sits bottom-right until dragged, arrow-keyed or swapped by its "Move to the other side" button
9 * to another corner; the corner is kept per app host in localStorage. It styles itself through the
10 * CSSOM (never a `style` attribute or a `<style>` element), which a strict `style-src` does not
11 * block.
1212 *
1313 * Its cost is stated: tag plus gzipped script stay under 8 KB (today ~7.6 KB), pinned by
1414 * test/toolbar-size.test.ts; the host is fixed, so the page never shifts.
@@ -516,7 +516,7 @@ const toolbarSource = `(function () {
516516 var NARROW_MAX = 600, CAMERA_TOP = "48px";
517517 function place(c) {
518518 corner = c;
519 var top = c.charAt(0) === "t", left = c.charAt(1) === "l";
519 var top = c[0] === "t", left = c[1] === "l";
520520 var narrow = top && window.innerWidth <= NARROW_MAX;
521521 host.style.top = top ? (narrow ? CAMERA_TOP : "12px") : "auto";
522522 // The cssText cap assumes a pill 12px down; 36px lower, the cap drops by as much.
@@ -564,18 +564,21 @@ const toolbarSource = `(function () {
564564 sr.setAttribute("role", "status");
565565 sr.style.cssText = "position:absolute;opacity:0";
566566 box.appendChild(sr);
567 function go(t, l) {
568 if (t + l === corner) return;
569 place(t + l);
570 store(KEY, corner);
571 sr.textContent = "Moved to the " + (t > "b" ? "top " : "bottom ") + (l > "m" ? "right" : "left");
572 }
567573 pill.addEventListener("keydown", function (e) {
568 var t = corner.charAt(0), l = corner.charAt(1);
574 var t = corner[0], l = corner[1];
569575 if (e.key === "ArrowLeft") l = "l";
570576 else if (e.key === "ArrowRight") l = "r";
571577 else if (e.key === "ArrowUp") t = "t";
572578 else if (e.key === "ArrowDown") t = "b";
573579 else return;
574580 e.preventDefault();
575 if (t + l === corner) return;
576 place(t + l);
577 store(KEY, corner);
578 sr.textContent = "Moved to the " + (t > "b" ? "top " : "bottom ") + (l > "m" ? "right" : "left");
581 go(t, l);
579582 });
580583 // An inline display beats the UA [hidden] rule, so display carries the state.
581584 function ring(b) {
@@ -590,6 +593,14 @@ const toolbarSource = `(function () {
590593 ring(x);
591594 x.addEventListener("click", function () { set(false); pill.focus(); });
592595 panel.appendChild(x);
596 // "Move to the other side": the keyboard's move, mirrored left/right. It sits in the panel, so
597 // the pill's own box does not change size.
598 var sw = document.createElement("button");
599 sw.textContent = "Move to the other side";
600 sw.style.cssText = "all:unset;" + LS;
601 ring(sw);
602 sw.addEventListener("click", function () { go(corner[0], corner[1] > "l" ? "l" : "r"); });
603 panel.appendChild(sw);
593604 // Dismissed for a week: the forge sets its own cookie; the page's are never touched here.
594605 var gone = document.createElement("button");
595606 gone.type = "button";
test/toolbar-swap.test.ts added +58
@@ -0,0 +1,58 @@
1 /** The panel's "Move to the other side" control (#14565): swap, remember, restore, fall back. */
2 import { describe, expect, test } from "bun:test";
3 import { boot } from "./helpers/toolbar-boot.ts";
4
5 const swap = (b: ReturnType<typeof boot>) => b.els().find((e) => e.textContent === "Move to the other side")!;
6
7 describe("moving the toolbar to the other side", () => {
8 test("the default side is bottom-right and the control is in the panel", () => {
9 const b = boot({});
10 expect(b.host.style.right).toBe("12px");
11 expect(swap(b)).toBeDefined();
12 });
13
14 test("it swaps left and right, keeps the height, and is kept per origin", () => {
15 const store: Record<string, string> = {};
16 const b = boot(store);
17 b.fire(swap(b), "click");
18 expect(b.host.style.left).toBe("12px");
19 expect(b.host.style.right).toBe("auto");
20 expect(b.host.style.bottom).toBe("12px");
21 expect(b.box.style.flexDirection).toBe("row");
22 expect(store["forge-pill-corner"]).toBe("bl");
23 b.fire(swap(b), "click");
24 expect(b.host.style.right).toBe("12px");
25 expect(store["forge-pill-corner"]).toBe("br");
26 });
27
28 test("a top corner swaps within the top and is announced", () => {
29 const store: Record<string, string> = { "forge-pill-corner": "tl" };
30 const b = boot(store);
31 b.fire(swap(b), "click");
32 expect(store["forge-pill-corner"]).toBe("tr");
33 const sr = b.box.children.find((c: any) => c.attrs.role === "status")!;
34 expect(sr.textContent).toBe("Moved to the top right");
35 });
36
37 test("the stored side is applied at boot, before any click", () => {
38 const b = boot({ "forge-pill-corner": "bl" });
39 expect(b.host.style.left).toBe("12px");
40 });
41
42 test("a bad stored value falls back to the default", () => {
43 const b = boot({ "forge-pill-corner": "zz" });
44 expect(b.host.style.right).toBe("12px");
45 expect(b.host.style.bottom).toBe("12px");
46 });
47
48 test("the button is a real, enabled button in the tab order, after the close button", () => {
49 const b = boot({});
50 const btns = b.els().filter((e: any) => e.tag === "button");
51 const close = btns.find((e: any) => e.attrs["aria-label"] === "Close")!;
52 const sw = swap(b);
53 expect(sw.tag).toBe("button");
54 expect(sw.disabled).toBeFalsy();
55 expect(sw.attrs.tabindex).toBeUndefined();
56 expect(btns.indexOf(sw)).toBeGreaterThan(btns.indexOf(close));
57 });
58 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs