Repository navigation
fix(web): keep focus when reopening settings navigation - #1311
Robert0622 wants to merge 1 commit into
Conversation
Move focus to the collapse button before the reopen button hides, and stop hiding the collapsed sidebar with a delayed visibility transition. Keep a short retry for frames where the button cannot take focus yet. (cherry picked from commit 917b176) Co-Authored-By: Claude Code <noreply@anthropic.com>
crispinhu27
left a comment
There was a problem hiding this comment.
初审结论:未发现阻塞问题,批准。审查与验证对应 head 565ef075(base main 177d8815)。
审查范围
web/app.js:#settingsSidebarExpand的点击处理、setSettingsSidebarExpanded(expanded, focusToggle)新增的同步焦点转移与reopen.hidden时序,以及其他调用方(路由切换、resize、reduced-motion 变化、窄屏、access.js)。最终的hidden、inert、aria-hidden状态与改动前一致。web/app/navigation.css:去掉了visibility过渡。收起状态改为由clip-path+pointer-events:none+inert+aria-hidden隐藏,窄屏下的 fixed 浮层规则也核对过。- e2e 新断言:在应用 click 处理之后记录
activeElement,可以区分「同步转移」和「下一帧补焦点」两种行为。
实际验证(本机原生部署,MySQL 8.4.9 全新库,head 和 base 各起一套,使用隔离账号与测试数据)
webtest:head 284/284,base 284/284。go test ./web/...通过。- e2e
desktop settings两个用例在 head 上 ×5 共 10/10 通过;03-workbench-settings.spec.mjs全文件 6 通过、2 跳过(缺第二用户 Token)。 - 基线对照:用本 PR 的 spec 跑 base,新断言失败(
Expected: "settingsSidebarToggle",Received: "",点击时焦点在 body 上),其余用例结果相同。说明这个断言确实覆盖了本次修复。 - Chromium 实测(reduce / no-preference 各跑一遍,head 与 base 对照):
- 鼠标点击、Enter、Space 展开,以及 Safari 式点击(焦点在 body,
element.click()):head 在 click 返回时焦点已经在#settingsSidebarToggle上;base 此时在BODY,要等下一帧才补上。 - 焦点在主内容区时展开,焦点不被抢走,两边一致。
- 收起后虽然 computed
visibility从 hidden 变成了 visible,但连按 Tab 40 次没有一次落进侧栏,elementFromPoint也命中不到侧栏。1440 宽下收起和展开的截图与 base 逐像素一致(只有顶栏动态文本差 13px)。900 和 390 宽下的状态与截图与 base 相同。 - 全程没有页面 JS 错误。
- 鼠标点击、Enter、Space 展开,以及 Safari 式点击(焦点在 body,
- CI 16/16 success(包括
core)。main 之后前进到c3dd1b4d(#1285、#1304),它对web/app.js和web/index.html的改动只涉及执行机器页,与设置导航无关,merge-tree无冲突。
以上是在上述版本与环境下的验证结果,不代表覆盖了所有浏览器(没有在真实 Safari/Firefox 上验证)。
|
结论:建议合入 GitHub 拒绝了 Pull Request Review 接口(HTTP 403:Tencent 组织启用了 OAuth App 访问限制)。当前账号无法提交正式 Approve / Request changes。以下改为普通评论。 核对了 |
Robert0622
left a comment
There was a problem hiding this comment.
CR + 部署实测(head 565ef075):LGTM
说明:这次评审的 token 是 PR 作者本人的账号,GitHub 不允许作者 approve 自己的 PR,所以只发评论、不点 Approve。
代码审查
setSettingsSidebarExpanded(true, …)在把展开按钮设为hidden之前,先把焦点交给#settingsSidebarToggle。焦点不会先掉到body上再被 rAF 拉回来,读屏器也不会先读一遍 body。- 焦点不在展开按钮上(例如点击时焦点已经在别处)就不抢焦点;
focusToggle的 rAF 重试只在焦点确实掉到 body 时才跑,最多 30 帧。 - CSS 去掉了
visibility的延迟过渡。隐藏状态仍保留clip-path和pointer-events: none,侧栏的aria-hidden逻辑没变,收起时不会误点到侧栏内容。 - 与最新 main
f3d4f41a合并无冲突(git merge-tree)。
部署实测(本机原生部署 PR 和 main 两个实例,MySQL 8.4.7 全新库,Chromium)
| 场景 | PR | main |
|---|---|---|
e2e/ui/03-workbench-settings.spec.mjs(PR 版本,含新断言「点击展开按钮的那一刻焦点已在收起按钮上」) |
7 passed / 1 skipped | 新断言失败:点击时焦点不在 settingsSidebarToggle |
| 同一 spec 的 main 版本 | — | 7 passed / 1 skipped |
键盘 Enter 重新展开后焦点、URL 停在 #/settings |
✅ | ✅ |
回归:webtest 284/284 通过(main 285/285;本分支落后 main 3 个提交,数量差来自 main 新增的用例)。
结论:没有发现问题,可以合入。
What changed
#settingsSidebarTogglebefore the expand button is hidden, so keyboard and pointer users never land on<body>.visibility; the collapsed sidebar staysinert.Split out of #1267 (originally commit 917b176 there) at reviewer request, since it is unrelated to long prompt delivery.
Validation
webtest284/284,go test ./web/...pass.desktop settingscases ine2e/ui/03-workbench-settings.spec.mjs×5 each: 10/10 pass, including the new "focus is already on the collapse button when clicked" assertion.<body>all focus#settingsSidebarToggle; reopening while focus is in the main content does not steal it; no JS errors.Safety
🤖 Generated with Claude Code