Skip to content

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

Merged
Robert0622 merged 2 commits into
mainfrom
codex/settings-nav-focus
Nov 25, 2026
Merged

Robert0622 merged 2 commits 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 previously approved these changes Nov 24, 2026

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

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

@Robert0622

Copy link
Copy Markdown
Collaborator Author

Pushed the narrow-viewport follow-up in fd4b595. All four settings-navigation Playwright regressions passed. On the deployed acceptance build, Chromium checks at 360, 480, 900, 1000, and 1440 px confirmed that collapse focuses the visible 44 px reopen button, reopening restores focus to the sidebar toggle, and both actions stay on the settings page.

@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 fd4b5955(base main 177d8815)。

复审背景

  • 之前在 565ef075 上的 APPROVE(6043658270)被新推送 dismiss,没有遗留的 Request Changes 问题。本轮重点审查增量提交 fd4b5955,同时复测之前已验证的焦点行为。

审查范围(增量)

  • web/app/navigation.css:删掉了 @media (max-width: 1000px) { .settings-navigation-reopen { display: none } },加上 flex-shrink: 0。[hidden] 规则仍然保留,所以非设置视图和侧栏展开时按钮照样隐藏;按钮由 setSettingsSidebarExpanded 统一控制 hidden,窄屏和宽屏走的是同一套逻辑。
  • 结合 web/app/frame.css 核对了窄屏规则:≤1000px 时 .platform-rail 是 display:none。在 base 上,直接打开 #/settings 时侧栏默认收起,展开按钮又被这条 media 规则隐藏,结果设置导航无法再打开。本次改动修复的正是这个问题。
  • e2e 新增 900/480px 用例:在 reduced motion 下,用键盘 Enter 收起、Space 展开,并断言焦点落点和 URL 不变。
  • main 现已前进到 848793b3,期间对 web/app.js 和 web/index.html 的改动只涉及 toast、沙箱选择和执行机器页,与设置导航无关,merge-tree 无冲突。

实际验证(本机原生部署,MySQL 8.4.7 全新库,head 和 base 各起一套,使用隔离账号和测试数据)

  • webtest 284/284,go test ./web/... 通过。
  • e2e 03-workbench-settings.spec.mjs,head 跑 ×3:3 个设置导航用例(desktop、900px、480px)9/9 全部通过。用同一份 spec 跑 base:这 3 个用例都失败,说明新断言确实覆盖了本次修复。
  • 同文件中「personal credentials: the add wizard…」在 head 上的 ×3 里有 1 次超时(卡在 confirm-delete 点击)。单独重跑 head ×5 全部通过,base ×5 也有 1 次超时,属于与本 PR 无关的既有偶发问题。
  • Chromium 实测,在 360/480/760/900/1000/1001/1440px 下各跑 reduce 和 no-preference 两遍,head 与 base 对照:
    • head 在 ≤1000px 直接打开设置时侧栏收起,展开按钮可见(44×44,elementFromPoint 命中按钮本身)。键盘 Enter/Space 和鼠标点击都能展开,展开后焦点在 #settingsSidebarToggle;收起后焦点回到展开按钮;URL 始终停在 #/settings。在窄屏侧栏中点「执行机器」后,侧栏收起,焦点落在展开按钮上。
    • base 在 ≤1000px 下展开按钮不可见,侧栏无法打开。
    • 顶栏没有元素重叠,也没有横向溢出(360px 时最右边元素在 348px 处)。切到非设置视图后展开按钮隐藏。≥1001px 的行为与 base 一致。全程没有页面 JS 错误。
  • CI 16/16 success。

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

@Robert0622

Copy link
Copy Markdown
Collaborator Author

Re-review of fd4b5955 (narrow-screen follow-up): LGTM, no blocking issues

Scope: only the delta 565ef075..fd4b5955 (web/app/navigation.css stops hiding .settings-navigation-reopen at ≤1000px; two new Playwright cases at 900/480px).

Deployed test (this head built locally, fresh MySQL 8.4.7, first account created via /api/auth/register, Chromium 156; not against this repo):

Width Collapse → reopen button visible Focus after collapse Space on reopen Focus after reopen URL stays #/settings
360 ✅ (68–112px, 44×44) #settingsSidebarExpand sidebar opens #settingsSidebarToggle ✅
480 ✅ #settingsSidebarExpand opens #settingsSidebarToggle ✅
900 ✅ (82–126px) #settingsSidebarExpand opens #settingsSidebarToggle ✅
1000 ✅ #settingsSidebarExpand opens #settingsSidebarToggle ✅
1440 ✅ (unchanged desktop path) #settingsSidebarExpand opens #settingsSidebarToggle ✅

Layout checks at 320/360/480/900/1000px with the sidebar collapsed: the reopen button overlaps no other topbar child, the topbar and document have no horizontal overflow, and the mobile .collab-rail-toggle is not visible at the same time, so there are no duplicate controls.

CI: 16/16 checks pass on fd4b5955.

Note: this token is the PR author's account, so this is a comment rather than a formal Approve. Screenshots are kept outside the repo; no screenshot branch was created.

@Robert0622
Robert0622 merged commit a1c474d into main Nov 25, 2026
16 checks passed
@Robert0622
Robert0622 deleted the codex/settings-nav-focus branch November 25, 2026 13:09
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