agent-office: Settings pickers read their value, keep open on overscroll, and the page's scrollbars are magpie's thin thumb (#778)

The three Settings pickers' buttons are labelled by the label and their
own value (aria-labelledby="lblScene optScene"), so they read "Scene
Office" again as the <select> did. .picker-list gets
overscroll-behavior: contain, so wheeling past a list's end no longer
scrolls #settings and closes it, and a #settings scroll in the frame a
picker opens repositions the list instead of closing it. The page's
scrollbars take magpie's thin thumb (8px, --faint, --muted on hover,
the same as magpie's Mac rule for pages), with --faint read from the
host's --magpie-faint token. Fixes #773. By frederick-wang.

Run on mote at c7ecc7a6 (Bun 1.4.2, HOME=mktemp -d):
packages/agent-office bun test 183 pass, 0 fail; bun scripts/check.mjs
exit 0; packages/agent-office stamp-page.mjs --check exit 0.
A Playwright script of the reviewer's own against the standalone page
(bin/agent-office.mjs --no-open, 600x520, chromium and webkit, light
and dark), run 4 times: the three accessible names are "Language
Auto", "Scene Office", "Quality Medium"; focus+Enter on #optQuality
keeps its list open; four 600px wheels over #optSceneList keep it open;
setting #settings' scrollTop still closes the picker; the list's
scrollbar is 8px with a #b9b9c2 thumb, #56565f under data-theme=dark;
no page errors.
Broken by hand: the same script at the base 10a61c2e fails the three
names in every engine and theme, and focus+Enter closed the Quality
list in 2 of 4 runs (the #773 race); the thumb is transparent there.
Not tried: test/browser.mjs inside a real magpie host window (needs a
magpie web URL); the wheel check also passes at the base in headless
Chromium and WebKit, so it does not prove the overscroll fix.
This commit is contained in:
Zhaoji Wang
2026-11-06 11:08:29 +08:00
committed by GitHub
parent 367e879cab
commit 133cd35107
5 changed files with 59 additions and 14 deletions
+11 -3
View File
@@ -295,10 +295,18 @@ test("the Settings chevron and Language, Scene and Quality pickers are SVG app m
expect(html).not.toContain("⌄")
expect(html).not.toContain("<select")
expect(html).toMatch(/id="settingsBtn"[^>]*><span data-t="settings">Settings<\/span><svg class="chev" viewBox="0 0 10 6"/)
for (const [btnId, listId] of [["optLang", "optLangList"], ["optScene", "optSceneList"], ["optQuality", "optQualityList"]]) {
expect(html).toMatch(new RegExp(`<button[^>]*id="${btnId}"[^>]*aria-haspopup="listbox"[^>]*aria-expanded="false"[^>]*aria-controls="${listId}"[^>]*>.*<svg class="chev" viewBox="0 0 10 6"`))
expect(html).toMatch(new RegExp(`<div[^>]*id="${listId}"[^>]*role="listbox"`))
for (const [lblId, btnId, listId] of [["lblLang", "optLang", "optLangList"], ["lblScene", "optScene", "optSceneList"], ["lblQuality", "optQuality", "optQualityList"]]) {
expect(html).toMatch(new RegExp(`<button[^>]*id="${btnId}"[^>]*aria-labelledby="${lblId} ${btnId}"[^>]*aria-haspopup="listbox"[^>]*aria-expanded="false"[^>]*aria-controls="${listId}"[^>]*>.*<svg class="chev" viewBox="0 0 10 6"`))
expect(html).toMatch(new RegExp(`<div[^>]*id="${listId}"[^>]*role="listbox"[^>]*aria-labelledby="${lblId}"`))
}
expect(css).toContain("--faint: var(--magpie-faint, #b9b9c2);")
expect(css).toMatch(/\[data-theme="dark"\][^{]*\{[^}]*--faint:\s*var\(--magpie-faint,\s*#56565f\);/)
expect(css).toMatch(/::-webkit-scrollbar\s*\{\s*width:\s*8px;\s*height:\s*8px;\s*background:\s*transparent;\s*\}/)
expect(css).toMatch(/::-webkit-scrollbar-thumb\s*\{\s*background:\s*var\(--faint\);\s*border:\s*2px solid transparent;\s*border-radius:\s*8px;\s*background-clip:\s*padding-box;\s*\}/)
expect(css).toMatch(/::-webkit-scrollbar-thumb:hover\s*\{\s*background-color:\s*var\(--muted\);\s*\}/)
expect(css).toMatch(/::-webkit-scrollbar-button,\s*::-webkit-scrollbar-corner\s*\{\s*display:\s*none;\s*background:\s*transparent;\s*\}/)
expect(css).not.toContain("scrollbar-width")
expect(css).toMatch(/\.picker-list\s*\{[^}]*overscroll-behavior:\s*contain;/)
expect(css).toMatch(/\.btn\s*\{[^}]*display:\s*inline-flex;[^}]*align-items:\s*center;[^}]*gap:\s*7px;/)
expect(css).toContain(".today-tokens:empty { display: none; }")
expect(css).toContain('#settingsBtn[aria-expanded="true"] .chev, .lang-select[aria-expanded="true"] .chev { transform: rotate(180deg); }')
+17 -2
View File
@@ -763,6 +763,10 @@
const QUALITY_OPTIONS = [["low", "qLow"], ["medium", "qMedium"], ["high", "qHigh"]]
const pickers = []
let openPicker = null
let pickerOpeningFrame = 0
function clearPickerOpening() {
if (pickerOpeningFrame) { cancelAnimationFrame(pickerOpeningFrame); pickerOpeningFrame = 0 }
}
function checkIcon() {
const ns = "http://www.w3.org/2000/svg"
const s = document.createElementNS(ns, "svg")
@@ -847,7 +851,10 @@
list.style.maxHeight = maxH + "px"
}
function close(refocus) {
if (openPicker === api) openPicker = null
if (openPicker === api) {
openPicker = null
clearPickerOpening()
}
list.hidden = true
btn.setAttribute("aria-expanded", "false")
list.removeAttribute("aria-activedescendant")
@@ -864,6 +871,8 @@
list.hidden = false
btn.setAttribute("aria-expanded", "true")
openPicker = api
clearPickerOpening()
pickerOpeningFrame = requestAnimationFrame(() => { pickerOpeningFrame = 0 })
position()
setActive(idx)
list.focus({ preventScroll: true })
@@ -1106,7 +1115,13 @@
$("settingsBtn").addEventListener("click", (e) => { e.stopPropagation(); toggleMenu($("settingsBtn"), menu) })
$("todayBtn").addEventListener("click", (e) => { e.stopPropagation(); toggleMenu($("todayBtn"), todayMenu) })
menu.addEventListener("click", (e) => e.stopPropagation())
menu.addEventListener("scroll", () => closePicker(false))
// Focusing a picker button near the foot of a scrollable #settings menu
// queues an async scroll event on #settings for the same frame; reposition
// the newly opened list instead of closing it on that opening-frame scroll.
menu.addEventListener("scroll", () => {
if (pickerOpeningFrame) { if (openPicker) openPicker.position(); return }
closePicker(false)
})
todayMenu.addEventListener("click", (e) => e.stopPropagation())
addEventListener("pointerdown", (e) => {
if (openPicker && !openPicker.wrap.contains(e.target)) closePicker(false)
+5 -5
View File
@@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Agent Office</title>
<link rel="stylesheet" href="style.css?v=8702ccabcfcc">
<link rel="stylesheet" href="style.css?v=e2ef03f6ddcd">
<script src="_magpie/bridge.js"></script>
<script src="agents.js?v=d958111cd669"></script>
<script src="model.js?v=b04e2020da2a"></script>
@@ -12,7 +12,7 @@
<script src="scene.js?v=097cc0a3eec6"></script>
<script src="three.min.js?v=5b5a0ae404b6"></script>
<script src="scene3d.js?v=b666062a087d"></script>
<script src="app.js?v=5fca331c2ab2" defer></script>
<script src="app.js?v=a9ae93b3acc1" defer></script>
</head>
<body>
<main class="card" id="card">
@@ -59,21 +59,21 @@
<div class="row col">
<span id="lblLang" data-t="language">Language</span>
<div class="picker">
<button type="button" class="lang-select" id="optLang" aria-labelledby="lblLang" aria-haspopup="listbox" aria-expanded="false" aria-controls="optLangList"><span class="picker-val"></span><svg class="chev" viewBox="0 0 10 6" width="10" height="6" aria-hidden="true"><path d="M1.25 1.25L5 4.75L8.75 1.25" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
<button type="button" class="lang-select" id="optLang" aria-labelledby="lblLang optLang" aria-haspopup="listbox" aria-expanded="false" aria-controls="optLangList"><span class="picker-val"></span><svg class="chev" viewBox="0 0 10 6" width="10" height="6" aria-hidden="true"><path d="M1.25 1.25L5 4.75L8.75 1.25" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
<div class="picker-list" id="optLangList" role="listbox" aria-labelledby="lblLang" tabindex="-1" hidden></div>
</div>
</div>
<div class="row col">
<span id="lblScene" data-t="scene">Scene</span>
<div class="picker">
<button type="button" class="lang-select" id="optScene" aria-labelledby="lblScene" aria-haspopup="listbox" aria-expanded="false" aria-controls="optSceneList"><span class="picker-val"></span><svg class="chev" viewBox="0 0 10 6" width="10" height="6" aria-hidden="true"><path d="M1.25 1.25L5 4.75L8.75 1.25" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
<button type="button" class="lang-select" id="optScene" aria-labelledby="lblScene optScene" aria-haspopup="listbox" aria-expanded="false" aria-controls="optSceneList"><span class="picker-val"></span><svg class="chev" viewBox="0 0 10 6" width="10" height="6" aria-hidden="true"><path d="M1.25 1.25L5 4.75L8.75 1.25" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
<div class="picker-list" id="optSceneList" role="listbox" aria-labelledby="lblScene" tabindex="-1" hidden></div>
</div>
</div>
<div class="row col">
<span id="lblQuality" data-t="quality">Quality</span>
<div class="picker">
<button type="button" class="lang-select" id="optQuality" aria-labelledby="lblQuality" aria-haspopup="listbox" aria-expanded="false" aria-controls="optQualityList"><span class="picker-val"></span><svg class="chev" viewBox="0 0 10 6" width="10" height="6" aria-hidden="true"><path d="M1.25 1.25L5 4.75L8.75 1.25" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
<button type="button" class="lang-select" id="optQuality" aria-labelledby="lblQuality optQuality" aria-haspopup="listbox" aria-expanded="false" aria-controls="optQualityList"><span class="picker-val"></span><svg class="chev" viewBox="0 0 10 6" width="10" height="6" aria-hidden="true"><path d="M1.25 1.25L5 4.75L8.75 1.25" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
<div class="picker-list" id="optQualityList" role="listbox" aria-labelledby="lblQuality" tabindex="-1" hidden></div>
</div>
</div>
+7 -2
View File
@@ -3,6 +3,7 @@
--card: var(--magpie-card, #f6f6f7);
--fg: var(--magpie-fg, #1d1d1f);
--muted: var(--magpie-muted, #6e6e73);
--faint: var(--magpie-faint, #b9b9c2);
--line: var(--magpie-line, #e5e5ea);
--accent: var(--magpie-accent, #4f46e5);
--font: var(--magpie-font, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", system-ui, sans-serif);
@@ -10,7 +11,7 @@
--sheet: var(--card);
--think: #8b6cf6; --exec: #3b82f6; --reply: #10b981; --wait: #f59e0b; --done: #22a35a; --err: #ef4444;
}
[data-theme="dark"] { --sheet: #1c1c1f; }
[data-theme="dark"] { --faint: var(--magpie-faint, #56565f); --sheet: #1c1c1f; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* the page paints no background of its own: magpie's shows through, so
@@ -20,6 +21,10 @@ html, body { margin: 0; height: 100%; overflow: hidden; background: transparent;
window's inset shows no ring of a different colour */
body { padding: 18px 24px 12px; font: 13px/1.45 var(--font); }
button { font: inherit; color: inherit; }
::-webkit-scrollbar { width: 8px; height: 8px; background: transparent; }
::-webkit-scrollbar-thumb { background: var(--faint); border: 2px solid transparent; border-radius: 8px; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--muted); }
::-webkit-scrollbar-button, ::-webkit-scrollbar-corner { display: none; background: transparent; }
.card { display: flex; flex-direction: column; height: 100%; min-height: 0; }
body.panel, .card { background: none; }
@@ -204,7 +209,7 @@ footer { padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.lang-select { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--fg); font: inherit; font-size: 13px; text-align: left; cursor: pointer; }
.lang-select:hover, .lang-select[aria-expanded="true"] { border-color: var(--muted); }
.picker-val { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-list { position: fixed; z-index: 60; display: flex; flex-direction: column; gap: 1px; max-width: min(320px, calc(100vw - 16px)); max-height: 240px; overflow: auto; padding: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 30px rgba(0, 0, 0, .2); outline: none; }
.picker-list { position: fixed; z-index: 60; display: flex; flex-direction: column; gap: 1px; max-width: min(320px, calc(100vw - 16px)); max-height: 240px; overflow: auto; overscroll-behavior: contain; padding: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 30px rgba(0, 0, 0, .2); outline: none; }
.picker-opt { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; padding: 6px 8px; border: 0; border-radius: 7px; background: none; color: var(--fg); font: inherit; font-size: 13px; text-align: left; cursor: pointer; }
.picker-opt:hover, .picker-opt.active { background: var(--card); }
.picker-opt[aria-selected="true"] { font-weight: 600; }
+19 -2
View File
@@ -61,13 +61,27 @@ for(const engine of (process.env.OFFICE_BROWSERS||'chromium,webkit').split(','))
const bounds=await frame.locator('#'+id).evaluate(e=>{const r=e.getBoundingClientRect();return {left:r.left,right:r.right,top:r.top,bottom:r.bottom,w:innerWidth,h:innerHeight}})
assert(bounds.left>=0&&bounds.right<=bounds.w+1&&bounds.top>=0&&bounds.bottom<=bounds.h+1,`${engine} menu ${JSON.stringify(bounds)}`)
if(id==='settings') {
await frame.locator('#optQuality').scrollIntoViewIfNeeded()
await frame.locator('#optQuality').click()
const sceneA11y=await frame.evaluate(()=>`${document.querySelector('#lblScene').textContent.trim()} ${document.querySelector('#optScene .picker-val').textContent.trim()}`)
assert((await frame.locator('#settings').ariaSnapshot()).includes(`button "${sceneA11y}"`),`${engine} picker accessible name ${sceneA11y}`)
await frame.locator('#optQuality').focus()
await page.keyboard.press('Enter')
assert.equal(await frame.locator('#optQualityList').isVisible(),true,`${engine} same-frame focus+Enter keeps picker open`)
const pb=await frame.locator('#optQualityList').evaluate(e=>{const r=e.getBoundingClientRect();return {left:r.left,right:r.right,top:r.top,bottom:r.bottom,w:innerWidth,h:innerHeight}})
assert(pb.left>=0&&pb.right<=pb.w+1&&pb.top>=0&&pb.bottom<=pb.h+1,`${engine} picker ${JSON.stringify(pb)}`)
await page.keyboard.press('Escape')
assert.equal(await frame.locator('#optQualityList').isVisible(),false)
assert.equal(await frame.locator('#settings').isVisible(),true)
await frame.locator('#optScene').click()
const sceneBar=await frame.locator('#optSceneList').evaluate(e=>({overscroll:getComputedStyle(e).overscrollBehaviorY,width:getComputedStyle(e,'::-webkit-scrollbar').width,thumb:getComputedStyle(e,'::-webkit-scrollbar-thumb').backgroundColor}))
assert.equal(sceneBar.overscroll,'contain')
assert.equal(sceneBar.width,'8px')
assert.notEqual(sceneBar.thumb,'rgba(0, 0, 0, 0)')
const sceneBox=await frame.locator('#optSceneList').boundingBox()
await page.mouse.move(sceneBox.x+sceneBox.width/2,sceneBox.y+sceneBox.height/2)
await page.mouse.wheel(0,600)
await page.mouse.wheel(0,600)
assert.equal(await frame.locator('#optSceneList').isVisible(),true,`${engine} wheel overscroll keeps picker open`)
await page.keyboard.press('Escape')
}
await page.screenshot({path:`${output}/${engine}-${width}-${id}.png`})
await frame.locator(id==='settings'?'#settingsBtn':'#todayBtn').click()
@@ -105,6 +119,9 @@ for(const engine of (process.env.OFFICE_BROWSERS||'chromium,webkit').split(','))
await frame.locator('#settingsBtn').click()
}
await frame.locator('[data-mode="list"]').click()
const listBar=await frame.locator('#listview').evaluate(e=>({width:getComputedStyle(e,'::-webkit-scrollbar').width,thumb:getComputedStyle(e,'::-webkit-scrollbar-thumb').backgroundColor}))
assert.equal(listBar.width,'8px')
assert.notEqual(listBar.thumb,'rgba(0, 0, 0, 0)')
const buffer=await frame.locator('#office3d').evaluate(e=>[e.width,e.height])
await frame.evaluate(()=>{for(let i=0;i<5;i++)dispatchEvent(new Event('resize'));document.dispatchEvent(new Event('visibilitychange'))})
assert.deepEqual(await frame.locator('#office3d').evaluate(e=>[e.width,e.height]),buffer)