oficina / docs Public

Keep the phone toolbar's lists on the screen, and test every picker

With the room fixed in rastrillo, two placement faults were left in
Docs' own anchored lists. The font list, as wide as its widest row,
ran 6px off a 320px screen in Chromium and 21px in WebKit; it now
falls back to hanging from its box's other edge (position-try-fallbacks:
flip-inline) and is never wider than the screen. And a list select.js
opens upward got tokens.css's bottom: 100%, which for a fixed list is
the top of the viewport, so it sat wholly above the screen; it now
ends at its box's top.

fixtures/engines/pickers.mjs opens each picker at 320, 390 and 1280px
in Chromium and WebKit through the production stack and holds it to
its first five rows hit-testing as painted, the list inside the
viewport, and scrolling to its last row. A third leg forces the page's
anchor-positioning gate false in Chromium, for the wrapped bar a
browser without anchor positioning draws: Playwright's Firefox does
not launch here.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 656e961343f74c55eef3dcc06c1dd71211681cd9 parent b946538
4 files changed, +199 −0
  • fixtures/engines/pickers.mjs +161 −0
  • internal/docs/fonts_engines_browser_test.go +5 −0
  • internal/docs/toolbar_engines_browser_test.go +19 −0
  • internal/docs/views/show.html +14 −0
diff --git a/fixtures/engines/pickers.mjs b/fixtures/engines/pickers.mjs
new file mode 100644
index 0000000..4bf7a1c
--- /dev/null
+++ b/fixtures/engines/pickers.mjs
@@ -0,0 +1,161 @@
+// fixtures/engines/pickers.mjs — every toolbar picker opens to a list a
+// person can use, at a phone's width and a desktop's, in Chromium and in
+// WebKit (branch review on #91: on a 390px phone Style, Font and Size all
+// opened about 10px tall, and at 320px the font list ran 6px off the
+// screen).
+//
+// Run by internal/docs/toolbar_engines_browser_test.go with the same
+// DOCS_ENGINES_CONFIG as first-reveal.mjs.
+//
+// For each engine, at 320, 390 and 1280px wide, each picker is opened
+// with a click, as a person would, and must:
+//
+// 1. show its first five rows, each really painted there: the point at
+// a row's centre hits the row, so a list clipped by the toolbar or
+// covered by something fails even where its box measures right;
+// 2. lie inside the viewport, and leave the page no wider than it;
+// 3. scroll to its last row, if it has more than it shows.
+//
+// And at 390px, told only a band just below the toolbar is visible (as a
+// phone's keyboard does), a list that opens upward ends above its box and
+// still inside the screen; it had been wholly above it. Its rows are not
+// hit-tested: the title bar above the toolbar is drawn over them.
+//
+// A third leg is Chromium with the page's anchor-positioning gate forced
+// false: how a browser without anchor positioning (Firefox, when this was
+// written) draws the bar, which wraps instead of scrolling and leaves the
+// lists absolutely positioned and as wide as their widest row. Playwright's
+// Firefox does not launch on the machine this was written on, and
+// Chromium's anchor positioning cannot be switched off with a flag.
+
+const { chromium, webkit } = await import('playwright')
+
+const config = JSON.parse(process.env.DOCS_ENGINES_CONFIG)
+
+const widths = [
+ { width: 320, height: 568, phone: true },
+ { width: 390, height: 844, phone: true },
+ { width: 1280, height: 900, phone: false },
+]
+const pickers = ['block', 'font', 'size']
+
+// Two frames and a task: select.js places a list in a frame callback.
+const settle = () => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(() => setTimeout(r, 0))))
+
+// Measured in the page, with the list open.
+const measure = async (id) => {
+ const frame = () => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(() => setTimeout(r, 0))))
+ const input = document.getElementById(id)
+ const wrap = input.closest('[rst-combo]')
+ const list = wrap.querySelector('[rst-combo-list]')
+ const vw = document.documentElement.clientWidth
+ const vh = window.innerHeight
+ const lr = list.getBoundingClientRect()
+ const rows = [...list.querySelectorAll('[rst-combo-option]')].filter((li) => !li.hidden && li.getClientRects().length)
+ const painted = (li) => {
+ const r = li.getBoundingClientRect()
+ if (r.height <= 0 || r.top < lr.top - 0.5 || r.bottom > lr.bottom + 0.5) return false
+ const hit = document.elementFromPoint(Math.min(r.left + r.width / 2, vw - 1), r.top + r.height / 2)
+ return !!hit && li.contains(hit)
+ }
+ const out = {
+ open: !list.hidden && input.getAttribute('aria-expanded') === 'true',
+ up: wrap.hasAttribute('rst-combo-up'),
+ rows: rows.length,
+ list: { left: Math.round(lr.left), right: Math.round(lr.right), top: Math.round(lr.top), bottom: Math.round(lr.bottom), height: Math.round(lr.height) },
+ box: (({ top, bottom }) => ({ top: Math.round(top), bottom: Math.round(bottom) }))(wrap.getBoundingClientRect()),
+ viewport: { width: vw, height: vh },
+ pageWidth: document.documentElement.scrollWidth,
+ shown: rows.slice(0, 5).filter(painted).length,
+ }
+ out.inside = lr.left >= -0.5 && lr.right <= vw + 0.5 && lr.top >= -0.5 && lr.bottom <= vh + 0.5
+ out.scrolls = list.scrollHeight > list.clientHeight + 1
+ if (out.scrolls) {
+ list.scrollTop = list.scrollHeight
+ await frame()
+ out.scrolledTo = list.scrollTop
+ out.lastShown = painted(rows[rows.length - 1])
+ } else {
+ out.lastShown = rows.length > 0 && painted(rows[rows.length - 1])
+ }
+ return out
+}
+
+const gate = '@supports (anchor-name: --docs-probe)'
+const legs = {
+ chromium: { engine: chromium },
+ webkit: { engine: webkit },
+ 'chromium without anchor positioning': { engine: chromium, noAnchor: true },
+}
+
+const failures = []
+const results = []
+for (const [engineName, leg] of Object.entries(legs).filter(([n, l]) => !process.env.DOCS_ENGINES_ENGINE || l.engine.name() === process.env.DOCS_ENGINES_ENGINE)) {
+ const browser = await leg.engine.launch({ headless: true })
+ for (const size of widths) {
+ const context = await browser.newContext({
+ viewport: { width: size.width, height: size.height },
+ deviceScaleFactor: 1,
+ // A phone's coarse pointer, which takes the rows to 44px.
+ hasTouch: size.phone,
+ })
+ await context.addCookies(config.cookies.map((c) => ({ name: c.Name, value: c.Value, url: config.origin, httpOnly: c.HttpOnly, sameSite: 'Lax' })))
+ if (leg.noAnchor) {
+ await context.route('**/d/*', async (route) => {
+ const response = await route.fetch()
+ const body = await response.text()
+ if (!body.includes(gate)) failures.push(`${engineName}: the page has no anchor-positioning gate to force false`)
+ await route.fulfill({ response, body: body.replaceAll(gate, '@supports (anchor-name: --docs-probe) and (not (display: block))') })
+ })
+ }
+ const page = await context.newPage()
+ const at = `${engineName} at ${size.width}px`
+ const fail = (msg) => failures.push(`${at}: ${msg}`)
+ await page.goto(config.origin + '/d/' + config.docs.simple.shift())
+ await page.waitForSelector('[docs-text][contenteditable="true"]', { timeout: 30000 })
+ await page.waitForSelector('#docs-select-font-combo:not([disabled])', { timeout: 30000 })
+
+ for (const kind of pickers) {
+ const id = `docs-select-${kind}-combo`
+ await page.click('#' + id)
+ await page.evaluate(settle)
+ const m = await page.evaluate(measure, id)
+ results.push({ at, kind, ...m })
+ if (!m.open) fail(`${kind}: the list did not open`)
+ if (m.shown < Math.min(5, m.rows)) fail(`${kind}: ${m.shown} of its first ${Math.min(5, m.rows)} rows can be seen; the list is ${m.list.height}px tall at ${m.list.top}..${m.list.bottom}`)
+ if (!m.inside) fail(`${kind}: the list spans ${m.list.left}..${m.list.right} x ${m.list.top}..${m.list.bottom}, outside the ${m.viewport.width}x${m.viewport.height} viewport`)
+ if (m.pageWidth > m.viewport.width) fail(`${kind}: with the list open the page is ${m.pageWidth}px wide in a ${m.viewport.width}px viewport`)
+ if (m.scrolls && !(m.scrolledTo > 0)) fail(`${kind}: the list has more rows than it shows but does not scroll`)
+ if (!m.lastShown) fail(`${kind}: its last row cannot be reached`)
+ await page.keyboard.press('Escape')
+ await page.evaluate(() => document.activeElement && document.activeElement.blur())
+ }
+
+ if (size.width === 390) {
+ // A keyboard over everything but the toolbar and 40px under it:
+ // there is more room above the box, so the list opens upward.
+ const id = 'docs-select-block-combo'
+ await page.evaluate((id) => {
+ const box = document.getElementById(id).closest('[rst-combo]').getBoundingClientRect()
+ document.dispatchEvent(new CustomEvent('rst:select-viewport', { detail: { top: 0, bottom: box.bottom + 40 } }))
+ }, id)
+ await page.click('#' + id)
+ await page.evaluate(settle)
+ const m = await page.evaluate(measure, id)
+ results.push({ at, kind: 'block, upward', ...m })
+ if (!m.up) fail(`block, upward: the list did not open upward with ${m.box.top}px above its box and 40px below`)
+ if (m.list.bottom > m.box.top + 1 || m.list.top < 0 || m.list.height < 20) fail(`block, upward: the list spans ${m.list.top}..${m.list.bottom} with its box at ${m.box.top}; want above the box and inside the screen`)
+ await page.keyboard.press('Escape')
+ await page.evaluate(() => document.dispatchEvent(new CustomEvent('rst:select-viewport', { detail: null })))
+ }
+ await context.close()
+ }
+ await browser.close()
+}
+
+for (const r of results) console.log(JSON.stringify(r))
+if (failures.length) {
+ console.log('FAIL\n' + failures.join('\n'))
+ process.exit(1)
+}
+console.log('ok: every picker opens to a usable list, inside the viewport, in every engine and width')
diff --git a/internal/docs/fonts_engines_browser_test.go b/internal/docs/fonts_engines_browser_test.go
index 19851cd..3bd30c4 100644
--- a/internal/docs/fonts_engines_browser_test.go
+++ b/internal/docs/fonts_engines_browser_test.go
@@ -90,6 +90,11 @@ func runEnginesApp(t *testing.T, script string) (string, *docs.App, error) {
names = append(names, "replay")
perName["replay"] = 2 * 11
}
+ // The pickers (pickers.mjs): one simple document per leg and width.
+ if script == "pickers.mjs" {
+ names = []string{"simple"}
+ perName["simple"] = 3 * 3
+ }
for _, name := range names {
vector := name
if name == "replay" {
diff --git a/internal/docs/toolbar_engines_browser_test.go b/internal/docs/toolbar_engines_browser_test.go
new file mode 100644
index 0000000..fcc7a98
--- /dev/null
+++ b/internal/docs/toolbar_engines_browser_test.go
@@ -0,0 +1,19 @@
+//go:build browser
+
+package docs_test
+
+import "testing"
+
+// Every toolbar picker opens to a list a person can use, at 320, 390 and
+// 1280px, in WebKit as well as Chromium: its first five rows on screen,
+// the list inside the viewport and scrolling to its last row
+// (fixtures/engines/pickers.mjs). On a 390px phone Style, Font and Size
+// all opened about 10px tall: the toolbar scrolls sideways there, and
+// ui/select.js took it for the edge of a list fixed and anchored out of
+// it (branch review on #91). At 320px the font list ran 6px off the
+// screen.
+func TestToolbarEnginesEveryPickerOpensUsably(t *testing.T) {
+ if out, err := runEngines(t, "pickers.mjs"); err != nil {
+ t.Fatalf("a toolbar picker does not open to a usable list in every engine: %v\n%s", err, out)
+ }
+}
diff --git a/internal/docs/views/show.html b/internal/docs/views/show.html
index bea386a..8593ae3 100644
--- a/internal/docs/views/show.html
+++ b/internal/docs/views/show.html
@@ -1093,6 +1093,10 @@
[docs-toolbar] [rst-combo]:has(#docs-select-block-combo) [rst-combo-list] { position-anchor: --docs-select-block; }
[docs-toolbar] [rst-combo]:has(#docs-select-font-combo) [rst-combo-list] { position-anchor: --docs-select-font; }
[docs-toolbar] [rst-combo]:has(#docs-select-size-combo) [rst-combo-list] { position-anchor: --docs-select-size; }
+ /* A list as wide as its widest row can run off the screen from a
+ box near its end (the font list did, by 6px at 320px): it then
+ hangs from the box's other edge, and is never wider than the
+ screen. */
[docs-toolbar] [rst-combo-list] {
position: fixed;
inset: auto;
@@ -1100,6 +1104,16 @@
left: anchor(left);
min-inline-size: anchor-size(width);
inline-size: max-content;
+ max-inline-size: calc(100vw - 2 * var(--rst-sp-2));
+ position-try-fallbacks: flip-inline;
+ }
+ /* ui/select.js opens a list upward when there is more room above,
+ and tokens.css then sets bottom: 100% and top: auto, at a weight
+ that beats the rule above. For a fixed list that is 100% of the
+ viewport: the list sat wholly above the screen. */
+ [docs-toolbar] [rst-combo][rst-combo-up] [rst-combo-list] {
+ top: auto;
+ bottom: anchor(top);
}
}
}