Skip to content

fix(web): keep focus when reopening settings navigation - #1311

Open
Robert0622 wants to merge 1 commit into
mainfrom
codex/settings-nav-focus
Open

Robert0622 wants to merge 1 commit into
mainfrom
codex/settings-nav-focus

Conversation

@Robert0622

Copy link
Copy Markdown
Collaborator

What changed

  • Reopening the collapsed settings navigation moves focus to #settingsSidebarToggle before the expand button is hidden, so keyboard and pointer users never land on <body>.
  • The collapse and enter animations no longer transition visibility; the collapsed sidebar stays inert.
  • Keeps main's 30-frame focus retry fallback, which the existing e2e case relies on when the button cannot take focus immediately.

Split out of #1267 (originally commit 917b176 there) at reviewer request, since it is unrelated to long prompt delivery.

Validation

  • webtest 284/284, go test ./web/... pass.
  • e2e desktop settings cases in e2e/ui/03-workbench-settings.spec.mjs ×5 each: 10/10 pass, including the new "focus is already on the collapse button when clicked" assertion.
  • Browser check on a local instance: reopening by keyboard, by mouse, and with focus on <body> all focus #settingsSidebarToggle; reopening while focus is in the main content does not steal it; no JS errors.

Safety

  • I did not include credentials, internal endpoints, production data, or organization-specific infrastructure.
  • I preserved user files and unrelated changes.

🤖 Generated with Claude Code

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 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

初审结论:未发现阻塞问题,批准。审查与验证对应 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 错误。
  • CI 16/16 success(包括 core)。main 之后前进到 c3dd1b4d(#1285、#1304),它对 web/app.js 和 web/index.html 的改动只涉及执行机器页,与设置导航无关,merge-tree 无冲突。

以上是在上述版本与环境下的验证结果,不代表覆盖了所有浏览器(没有在真实 Safari/Firefox 上验证)。

@cocofhu00

Copy link
Copy Markdown
Contributor

结论:建议合入

GitHub 拒绝了 Pull Request Review 接口(HTTP 403:Tencent 组织启用了 OAuth App 访问限制)。当前账号无法提交正式 Approve / Request changes。以下改为普通评论。

核对了 web/app.js 的 setSettingsSidebarExpanded:展开时若焦点在展开按钮或 body 上,会先把焦点移到 #settingsSidebarToggle,再隐藏展开按钮;点按路径保留了最多 30 帧的补焦。web/app/navigation.css 去掉了 visibility 过渡,避免焦点在隐藏瞬间落到 body。e2e/ui/03-workbench-settings.spec.mjs 断言了点击当下焦点已经在切换按钮上。与 main 无冲突,检查项均成功。可以合入。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 新增的用例)。

结论:没有发现问题,可以合入。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants