Public: anyone can read this; the crew can change it.
The command palette is great on a phone: one tap, type, go, like Spotlight #10651
mason/forge:mason/10435-the-command-palette-is-great-on-a-phone → main 5 commits fork
5 files
changed +83
−2
docs/design/areas/palette.md +7
| @@ -15,3 +15,10 @@ The palette's tell row (`data-tell`, last in the list) sends the typed sentence | ||
| 15 | 15 | ## Keys beside their actions |
| 16 | 16 | |
| 17 | 17 | An action's shortcut takes no room at rest (#8930, changing the "beside the action" rule of #8709). `btn`, `tabs`, the top bar, the feed's Dismiss and the review verdicts carry `data-hint` (`hintAttr()` in `ui.ts`); a `::before` draws it as a tooltip on hover or focus, and over every action while Option is held or after `?` (`html[data-hints]`, set by the shell script; Escape or a second `?` clears it). It is an overlay: nothing moves, and on touch-only screens it is not drawn. `.keyhint`, the inline `<kbd>`, stays only in menu items, where a column holds it; design-lint's `keyhint` rule refuses it elsewhere. A second `?` opens the help, which lists every key. |
| 18 | ||
| 19 | ## On a phone | |
| 20 | ||
| 21 | Under 720px the palette is a full-screen sheet that follows `visualViewport`, so the keyboard never covers results. | |
| 22 | ||
| 23 | - `.palette-fab` — the bottom-right search button that opens it with one tap; hidden on wide screens, where ⌘K, Ctrl-K and `/` do. | |
| 24 | - The grip (`.palette::before`) — the small bar at the top of the sheet that says it can be swiped down to close. |
src/web/client.ts +11
| @@ -2085,6 +2085,17 @@ const shellCore = /* js */ ` | ||
| 2085 | 2085 | } |
| 2086 | 2086 | }; |
| 2087 | 2087 | input.focus(); |
| 2088 | sheetFollowsKeyboard(dlg, list); | |
| 2089 | } | |
| 2090 | // On a phone the sheet tracks the visual viewport; a swipe down from the top closes it. | |
| 2091 | function sheetFollowsKeyboard(dlg, list) { | |
| 2092 | var vv = window.visualViewport, y0 = null, s = dlg.style; | |
| 2093 | function fit() { s.setProperty('--vvh', vv.height + 'px'); s.setProperty('--vvt', vv.offsetTop + 'px'); } | |
| 2094 | function down(e) { y0 = e.touches.length === 1 && !list.scrollTop ? e.touches[0].clientY : null; } | |
| 2095 | function move(e) { if (y0 !== null && e.touches[0].clientY - y0 > 90) { y0 = null; closePalette(); } } | |
| 2096 | if (vv) { fit(); vv.onresize = vv.onscroll = fit; } | |
| 2097 | dlg.ontouchstart = down; dlg.ontouchmove = move; | |
| 2098 | dlg.addEventListener('close', function () { if (vv) vv.onresize = vv.onscroll = null; }, { once: true }); | |
| 2088 | 2099 | } |
| 2089 | 2100 | doc.querySelectorAll('[data-palette]').forEach(function (b) { |
| 2090 | 2101 | b.addEventListener('click', function (e) { e.preventDefault(); openPalette(); }); |
src/web/layout.ts +8 −2
| @@ -384,7 +384,7 @@ function searchBar(): Html { | ||
| 384 | 384 | /> |
| 385 | 385 | ${kbd(["/"])} |
| 386 | 386 | </form> |
| 387 | <a class="btn btn-icon hide-lg" href="/search" aria-label="Search" | |
| 387 | <a class="btn btn-icon hide-lg" href="/search" aria-label="Search" data-palette | |
| 388 | 388 | >${icon("search")}</a |
| 389 | 389 | >`; |
| 390 | 390 | } |
| @@ -560,7 +560,13 @@ function paletteIndex(ctx: Ctx, extra: PaletteItem[]): Html { | ||
| 560 | 560 | * one that should close the dialog. |
| 561 | 561 | */ |
| 562 | 562 | function overlays(): Html { |
| 563 | return html`<dialog | |
| 563 | return html`<button | |
| 564 | class="palette-fab" | |
| 565 | data-palette | |
| 566 | > | |
| 567 | ${icon("search")}<span>Search</span> | |
| 568 | </button> | |
| 569 | <dialog | |
| 564 | 570 | class="dialog palette" |
| 565 | 571 | id="palette" |
| 566 | 572 | role="dialog" |
src/web/style/components.ts +27
| @@ -769,6 +769,33 @@ details[open] > summary.row > .row-lead { transform: rotate(90deg); } | ||
| 769 | 769 | @media (max-width: 719px) { |
| 770 | 770 | .palette { width: 100%; max-width: 100%; margin: auto auto 0; } |
| 771 | 771 | } |
| 772 | /* On a phone the palette is a full-screen sheet. The script sets --vvh and | |
| 773 | --vvt from visualViewport so the keyboard never covers a result; the | |
| 774 | fallbacks are the plain dynamic viewport. */ | |
| 775 | :root.js .palette-fab { display: none; } | |
| 776 | @media (max-width: 719px) { | |
| 777 | .palette { | |
| 778 | position: fixed; inset: 0; width: 100%; max-width: 100%; margin: 0; | |
| 779 | height: var(--vvh, 100dvh); max-height: none; top: var(--vvt, 0); | |
| 780 | border: 0; border-radius: 0; display: flex; flex-direction: column; | |
| 781 | padding-top: env(safe-area-inset-top); | |
| 782 | padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); | |
| 783 | } | |
| 784 | .palette:not([open]) { display: none; } | |
| 785 | .palette::before { content: ''; display: block; flex: none; width: 36px; height: 4px; margin: 8px auto 0; border-radius: 2px; background: var(--border); } | |
| 786 | .palette .palette-input { flex: none; min-height: 52px; } | |
| 787 | .palette-list { flex: 1 1 auto; height: auto; min-height: 0; padding-bottom: max(6px, env(safe-area-inset-bottom)); } | |
| 788 | .palette-item { min-height: 44px; } | |
| 789 | .palette-foot { display: none; } | |
| 790 | :root.js .palette-fab { | |
| 791 | position: fixed; z-index: 40; right: max(16px, env(safe-area-inset-right)); | |
| 792 | bottom: max(16px, env(safe-area-inset-bottom)); | |
| 793 | display: inline-flex; align-items: center; gap: 8px; min-height: 48px; padding: 0 18px; | |
| 794 | border: 1px solid var(--border); border-radius: 24px; | |
| 795 | background: var(--bg); color: var(--fg); box-shadow: var(--shadow-2); font-size: 15px; | |
| 796 | } | |
| 797 | } | |
| 798 | html:has(.palette[open]) { overflow: hidden; } | |
| 772 | 799 | .palette .palette-input { |
| 773 | 800 | width: 100%; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; |
| 774 | 801 | min-height: 48px; padding: 0 16px; background: none; font-size: 15px; box-shadow: none; |
test/palette.test.ts +30
| @@ -175,3 +175,33 @@ describe("the page runs the same functions", () => { | ||
| 175 | 175 | expect(shellJs).not.toContain("${"); |
| 176 | 176 | }); |
| 177 | 177 | }); |
| 178 | ||
| 179 | describe("the palette on a phone", () => { | |
| 180 | const rows: PaletteRow[] = [ | |
| 181 | { t: "trevato/morning-paper", h: "/trevato/morning-paper", g: "Repositories", n: "morning-paper" }, | |
| 182 | { t: "trevato/mapmaker", h: "/trevato/mapmaker", g: "Repositories", n: "mapmaker" }, | |
| 183 | { t: "Account settings", h: "/settings", g: "Settings" }, | |
| 184 | ]; | |
| 185 | ||
| 186 | test("typing 'paper' puts trevato/morning-paper first", () => { | |
| 187 | const hits = rankPalette(rows, "paper", [], 20).flatMap((g) => g.rows); | |
| 188 | expect(hits[0]?.h).toBe("/trevato/morning-paper"); | |
| 189 | }); | |
| 190 | ||
| 191 | test("initials find it: 'mp' reaches morning-paper", () => { | |
| 192 | const hits = rankPalette(rows, "mp", [], 20).flatMap((g) => g.rows); | |
| 193 | expect(hits.map((r) => r.h)).toContain("/trevato/morning-paper"); | |
| 194 | }); | |
| 195 | ||
| 196 | test("an empty query shows what you used last, first", () => { | |
| 197 | const recent = [{ t: "Account settings", h: "/settings", g: "Recent" }]; | |
| 198 | const hits = rankPalette([...recent, ...rows], "", ["/settings"], 24).flatMap((g) => g.rows); | |
| 199 | expect(hits[0]?.h).toBe("/settings"); | |
| 200 | }); | |
| 201 | ||
| 202 | test("the shell opens a keyboard-aware, swipe-closable sheet from one tap", () => { | |
| 203 | expect(shellJs).toContain("visualViewport"); | |
| 204 | expect(shellJs).toContain("sheetFollowsKeyboard"); | |
| 205 | expect(shellJs).toContain("input.focus()"); | |
| 206 | }); | |
| 207 | }); |
new above
offline