fix(web): align chat row icons and standardize interaction surfaces

This commit is contained in:
2026-10-21 01:33:33 +01:00
parent 2c1d5ccd47
commit 4ab49a2749
4 changed files with 125 additions and 37 deletions
+88 -7
View File
@@ -14,6 +14,7 @@ const html = `<!doctype html><meta charset="utf-8"><meta name="viewport" content
${["design/tokens/tokens", "base", "shell", "lists", "run-detail", "chat", "dialogs"].map(n => `<link rel="stylesheet" href="/${n}.css">`).join("")}
<style>body { margin: 0; } #fixture { display: flex; height: calc(100dvh - 80px); max-width: 540px; margin: 40px auto; } #fixture > .chat-list { flex: 1; }</style>
<div id="fixture"></div>
<div style="position:fixed;top:-1000px;left:0"><button id="ghostBaseline" class="ghost">Ordinary ghost</button><button id="rowBaseline" class="row">Ordinary row</button></div>
<script type="module">
import { createChatView } from '/src/views/chat.js';
import { newChatThread } from '/src/chat.js';
@@ -58,6 +59,7 @@ await new Promise(r => server.listen(0, "127.0.0.1", r));
let browser, mouse;
const captures = [];
const measurements = [];
const styleComparisons = [];
try {
browser = await launchChrome();
const page = await browser.openPage(`http://127.0.0.1:${server.address().port}/`);
@@ -67,19 +69,73 @@ try {
mouse = new WebSocket(target.webSocketDebuggerUrl);
await new Promise(r => mouse.addEventListener('open', r, {once:true}));
let sequence = 0;
const move = (x, y) => new Promise((resolve, reject) => {
const command = (method, params = {}) => new Promise((resolve, reject) => {
const id = ++sequence;
const listener = event => {
const response = JSON.parse(event.data);
if (response.id !== id) return;
mouse.removeEventListener('message', listener);
response.error ? reject(Error(response.error.message)) : resolve();
response.error ? reject(Error(response.error.message)) : resolve(response.result);
};
mouse.addEventListener('message', listener);
mouse.send(JSON.stringify({id,method:'Input.dispatchMouseEvent',params:{type:'mouseMoved',x,y}}));
mouse.send(JSON.stringify({id,method,params}));
});
const move = (x, y) => command('Input.dispatchMouseEvent', {type:'mouseMoved',x,y});
await command('DOM.enable');
await command('CSS.enable');
const {root:documentRoot} = await command('DOM.getDocument');
const force = async (selector, forcedPseudoClasses) => {
const {nodeId} = await command('DOM.querySelector', {nodeId:documentRoot.nodeId,selector});
await command('CSS.forcePseudoState', {nodeId,forcedPseudoClasses});
};
const styles = selector => page.evaluate(`(() => {
const s=getComputedStyle(document.querySelector(${JSON.stringify(selector)}));
return Object.fromEntries(['backgroundColor','borderTopColor','borderTopWidth','borderRadius','boxShadow','color',
'outlineColor','outlineWidth','outlineStyle','outlineOffset'].map(key=>[key,s[key]]));
})()`);
const compareStyles = async (width, coarse = false) => {
await move(1,1);
await page.evaluate('document.activeElement.blur()');
for (const state of [[],['hover'],['active'],['hover','active'],['focus-visible']]) {
const selectors=['#ghostBaseline','[data-session=streaming] .chat-star','[data-session=streaming] .chat-menu-button'];
for (const selector of selectors) await force(selector,state);
// Allow the shared background/border transitions to settle before comparing.
await page.evaluate('new Promise(r=>setTimeout(r,250))');
const baseline=await styles('#ghostBaseline');
for (const selector of selectors.slice(1)) assert.deepEqual(await styles(selector),baseline,`${selector}: ghost ${state}`);
await force('[data-session=selected] .chat-star',state);
await page.evaluate('new Promise(r=>setTimeout(r,250))');
const starred=await styles('[data-session=selected] .chat-star');
for (const key of ['backgroundColor','borderTopColor','borderTopWidth','borderRadius','boxShadow','outlineWidth','outlineStyle','outlineOffset']) assert.equal(starred[key],baseline[key],`starred ghost ${state}: ${key}`);
assert.equal(starred.color,await page.evaluate("(() => {const el=document.createElement('span');el.style.color='var(--color-accent)';document.body.append(el);const color=getComputedStyle(el).color;el.remove();return color;})()"),'starred state alone keeps its accent');
await force('[data-session=selected] .chat-star',[]);
for (const selector of selectors) await force(selector,[]);
for (const selected of [false,true]) {
const row=selected?'[data-session=selected]':'[data-session=streaming]';
await page.evaluate(`document.querySelector('#rowBaseline').classList.toggle('selected',${selected})`);
await force('#rowBaseline',state);
await force(row,state.includes('hover')?['hover']:[]);
await force(row+' .chat-session-button',state);
await page.evaluate('new Promise(r=>setTimeout(r,250))');
const expected=await styles('#rowBaseline'), actual=await styles(row);
// Container and native row inherit the same row surface/focus tokens.
for (const key of ['backgroundColor','borderTopColor','borderTopWidth','borderRadius','boxShadow','outlineColor','outlineWidth','outlineStyle','outlineOffset']) {
assert.equal(actual[key],expected[key],`row selected=${selected} ${state}: ${key}`);
}
const inner=await styles(row+' .chat-session-button');
assert.equal(inner.backgroundColor,'rgba(0, 0, 0, 0)','no inner hover/press fill');
assert.equal(inner.boxShadow,'none','no inner inset');
assert.equal(inner.outlineStyle,'none','focus ring belongs to outer row');
styleComparisons.push({width,coarse,state,selected,ghost:baseline,starred,row:actual,inner});
if (!selected && state.includes('active') && !state.includes('hover') && !coarse) await capture(`active-surface-${width}`);
await force(row+' .chat-session-button',[]);
await force(row,[]);
await force('#rowBaseline',[]);
}
}
};
const capture = async name => {
const file = `${name}.png`;
const file = `topright-leftlogo-bottomright-${name}.png`;
await page.screenshot(resolve(out, file));
captures.push(file);
};
@@ -88,7 +144,15 @@ try {
return [...document.querySelectorAll('.chat-row')].map(row => {
const controls = [...row.querySelectorAll('.chat-star,.chat-menu-button')];
const content = [...row.querySelectorAll('.chat-session-button,.chat-backend-logo')];
return {id:row.dataset.session, controls:controls.map(button => {
const r=row.getBoundingClientRect(), s=getComputedStyle(row), logo=row.querySelector('.chat-backend-logo'), title=row.querySelector('.chat-row-title');
const star=controls[0].getBoundingClientRect(), more=controls[1].getBoundingClientRect();
return {id:row.dataset.session,
topRight:Math.abs(star.top-r.top-parseFloat(s.paddingTop))<1,
bottomRight:Math.abs(more.bottom-r.bottom+parseFloat(s.paddingBottom)+parseFloat(s.borderBottomWidth))<1,
sameRight:star.right===more.right && Math.abs(star.right-r.right+parseFloat(s.paddingRight))<1,
logoBeforeTitle:logo.parentElement===title.parentElement && logo.nextElementSibling===title && logo.getBoundingClientRect().right<=title.getBoundingClientRect().left,
logoNonshrink:getComputedStyle(logo).flexShrink==='0',
controls:controls.map(button => {
const r=button.getBoundingClientRect(), style=getComputedStyle(button);
return {width:r.width,height:r.height,x:r.x,y:r.y,opacity:getComputedStyle(button.parentElement).opacity,
transition:getComputedStyle(button.parentElement).transitionDuration,
@@ -106,6 +170,7 @@ try {
const before = await geometry();
measurements.push({width, rows:before});
assert.equal(before.length, 4);
for (const row of before) for (const key of ['topRight','bottomRight','sameRight','logoBeforeTitle','logoNonshrink']) assert.equal(row[key],true,`${row.id}: ${key}`);
for (const row of before) for (const button of row.controls) {
assert.ok(button.width >= 44 && button.height >= 44, `${row.id}: touch target`);
assert.equal(button.opacity, '1');
@@ -119,6 +184,10 @@ try {
assert.equal(await page.evaluate("document.querySelector('[data-session=streaming] .chat-backend-logo').dataset.activity"), 'streaming');
assert.equal(await page.evaluate("document.querySelector('[data-session=new] .chat-backend-logo').dataset.activity"), 'new');
await capture(`rows-visible-${width}`);
await compareStyles(width);
await page.evaluate("document.querySelector('[data-session=selected] .chat-session-button').style.minHeight='160px'");
assert.ok((await geometry()).every(row=>row.topRight && row.bottomRight && row.sameRight),'controls anchor to full row height, not two adjacent fixed rows');
await page.evaluate("document.querySelector('[data-session=selected] .chat-session-button').style.minHeight=''");
const first = before[0].controls[0];
await move(first.x + 22, first.y + 22);
assert.deepEqual(await geometry(), before, 'hover changes neither controls nor layout');
@@ -144,6 +213,13 @@ try {
await capture(`rows-menu-${width}`);
await page.evaluate('reset()');
await page.click('[data-session=streaming] .chat-menu-button');
assert.equal(await page.evaluate('state.chatMenu'), 'streaming');
assert.equal(await page.evaluate('state.chatActiveId'), 'selected');
assert.deepEqual(await page.evaluate('calls.routes'), []);
await capture(`rows-pointer-menu-${width}`);
await page.click('[data-session=streaming] .chat-menu-button');
assert.equal(await page.evaluate("document.querySelectorAll('.chat-menu-panel').length"), 0);
const stars = await page.evaluate('calls.stars.length');
await page.click('[data-session=streaming] .chat-star');
assert.deepEqual(await page.evaluate('calls.stars.at(-1)'), {id:'streaming',starred:true});
@@ -187,13 +263,18 @@ try {
}
await page.emulateTouch();
await page.resize(390, 844);
measurements.push({width:390,coarse:true,rows:await geometry()});
assert.ok((await geometry()).every(row => row.controls.every(button => button.width >= 48 && button.height >= 48)));
assert.ok((await geometry()).every(row => row.topRight && row.bottomRight && row.sameRight && row.logoBeforeTitle && row.logoNonshrink));
await compareStyles(390,true);
await capture('rows-coarse-pointer-390');
// Exactly one route dispatch for a thread click (all action tests dispatched 0).
await page.click('[data-session=selected] .chat-session-button');
assert.deepEqual(await page.evaluate('calls.routes'), [{kind:'chatSession',id:'selected'}]);
await writeFile(resolve(out, 'manifest.json'), JSON.stringify({captures, measurements, widths:[390,420,1100],fixture:'actual createChatView, mock repo/rt, no native chat'}, null, 2));
console.log(`PASS: visible stable controls, no hover menu/reveal, 44/48px targets, keyboard order, shared star API, preserved selected thread, single route dispatch, bottom menu hit-tests. Captures: ${out}`);
await page.click('[data-session=selected] .chat-backend-logo');
assert.deepEqual(await page.evaluate('calls.routes'), [{kind:'chatSession',id:'selected'},{kind:'chatSession',id:'selected'}], 'logo inside native session button dispatches once too');
await writeFile(resolve(out, 'manifest.json'), JSON.stringify({captures, measurements, styleComparisons, widths:[390,420,1100],fixture:'actual createChatView, mock repo/rt, no native chat'}, null, 2));
console.log(`PASS: top-right star, left-before-title logo, bottom-right more, common ghost/row computed styles (${styleComparisons.length} states), no hover reveal, 44/48px targets, keyboard order, shared star API, selected thread retained, single thread/logo click dispatch, bottom menu hit-tests. Captures: ${out}`);
} finally {
mouse?.close();
await browser?.close();