Skip to content

fix(agent-dashboard): restore focus when dismissing the drawer - #25640

Closed
kambarakun wants to merge 1 commit into
stablyai:mainfrom
kambarakun:fix/agent-dashboard-drawer-focus-return
Closed

kambarakun wants to merge 1 commit into
stablyai:mainfrom
kambarakun:fix/agent-dashboard-drawer-focus-return

Conversation

@kambarakun

@kambarakun kambarakun commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Closing the Agents drawer could leave keyboard focus on the page body. Escape and the Close button now return focus to the element that opened it. Clicking another input or opening an agent still keeps focus on the destination.

What Changed

  • Capture the opener on each committed open transition, including reopening during the exit animation.
  • Restore focus from the Sheet's close-autofocus lifecycle only when it would otherwise be lost. Ignore stale Content callbacks and unavailable openers.
  • Mark actual outside dismissal, successful agent reveal, and switching to a popout as intentional focus handoffs.
  • Add 18 component cases using the real Sheet and outside-dismiss hook, plus three real Electron scenarios. No shared Sheet, store, routing, or visual-design changes.

Why

This non-modal drawer is controlled by the store and has no Radix trigger. Radix's default close handling therefore cannot restore a trigger. Unconditional restoration would steal focus from an outside click or an agent pane. The drawer now owns that distinction while retaining its existing suppression of open autofocus.

Linked Issue

Fixes #25570

Visual Proof

Same sidebar → search → Escape sequence and disposable Electron fixture on both revisions. Before: activeElement is BODY; after: the exact sidebar BUTTON regains focus. These screenshots crop the same button and use a test-only inset focus outline; the outline is not a product styling change.

Before After
Before: keyboard focus falls to the page body After: keyboard focus returns to Agent Dashboard

Before source: d173514. Captured after source: 7de5f242dade7fb5c3d3ce3dfe8c4fa45af024e0. The automated scenario also checks Close, outside-terminal input, and agent reveal.

The current PR head is 3fea9d145c6cf5bb80bf9b0f06c14d1a00d1565e. It changes only the commit message to English; its tree, parent, and author are identical to the original tested commit 7de5f242dade7fb5c3d3ce3dfe8c4fa45af024e0. The screenshots, Electron results, and local three-agent reviews below were obtained before that amendment. Targeted lint, pnpm tc, the changed-code quality gate, and the same 52 files / 430 tests were rerun successfully immediately before amending. GitHub checks and reviews on the new head are tracked separately.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

macOS 26.5.2 arm64; Node 24.16.0, pnpm 12.8.1, Electron 43.7.5. All automated app launches used ORCA_BACKGROUND_LAUNCH=1 and disposable profiles through the existing fixture.

  • Before: focus component suite 8 failed / 10 passed, with expected opener assertions receiving BODY; real Electron Escape failed toBeFocused.
  • After: 52 related files / 430 tests pass; real Electron 3/3 pass (Escape/Close, outside terminal input and agent reveal, nested-menu Escape and reopening during the real exit animation).
  • The separate manual-check fixture passes its hidden smoke check (1/1). The author then ran the isolated visible fixture on macOS and reported successful keyboard reopening after dismissal, outside-terminal input, and typing immediately after Open worktree without clicking the terminal again. These are human-reported results, separate from the automated assertions; VoiceOver remains untested.
  • pnpm tc, pnpm build, and check:code-quality:changed pass.
  • pnpm lint stops on five mobile import-cycle warnings, reproduced on the exact upstream source baseline.
  • Optional pnpm typecheck:e2e reports the same 222 errors on baseline and candidate; no new entries remain. This config is currently not a CI gate.
  • The repository-wide unit suite was not run; the commands and logs list the 52 relevant files rather than claiming a full-suite pass. Windows, Linux, live SSH, native popout focus, and mobile UI were not exercised.

AI Disclosure

OpenAI Codex implemented and tested the change. An independent Codex worker (gpt-6.1-sol), CodeRabbit CLI 0.8.2, and Claude Opus 5.5 reviewed the same original tested commit (7de5f242dade7fb5c3d3ce3dfe8c4fa45af024e0). Codex and Claude used read-only review; neither reran tests. The author performed the three guided macOS checks above and reported their outcomes in the conversation. No real AI agent was launched for the Electron fixture; synthetic status points to a disposable shell pane.

Review

Review of that original tested commit found no P0/P1/P2 issues from independent Codex or Claude; CodeRabbit completed all three changed files with zero findings. No code change was needed during this review wave. The earlier animation-coverage concern was resolved with the passing Electron scenario. Navigation to a missing or not-yet-mounted pane remains governed by the existing reveal logic; this patch does not promise to repair that separate navigation behavior.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

The change is confined to renderer focus policy. It uses DOM focus handling without OS-specific shortcuts or paths. Local/SSH execution, folder-workspace routing, agent integrations, and Git providers keep their existing paths; related folder-workspace and host-routing tests pass, while live remote behavior is untested. There is no new IPC, persisted field, dependency, or global listener. Opener capture runs on open transitions and restoration on close; performance was assessed from the code, not benchmarked. UI styling is unchanged. Basic security review found no new data or privilege boundary. Native mobile UI was not exercised.

X: @kambarakun

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Validated source revision: 3fea9d145c6cf5bb80bf9b0f06c14d1a00d1565e; code tree is unchanged from the reviewed 7de5f242dade7fb5c3d3ce3dfe8c4fa45af024e0; upstream baseline: d17351401d7372f3f48cc3cdb423147d8c8e61c1.

@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 10eebf60-9f58-440e-a2c3-1ee0b7fd9741
📥 Commits

Reviewing files that changed from the base of the PR and between 8f846d4 and 7de5f242dade7fb5c3d3ce3dfe8c4fa45af024e0.

📒 Files selected for processing (3)
  • src/renderer/src/components/dashboard/AgentDashboardDrawer.focus.test.tsx
  • src/renderer/src/components/dashboard/AgentDashboardDrawer.tsx
  • tests/e2e/agent-dashboard-drawer-focus.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The drawer now records its opener and content when it opens. On close, it restores focus only when the opener remains eligible and focus has not moved elsewhere. Agent reveal, pop-out, and outside dismissal use focus handoffs. New unit and end-to-end tests cover these paths, opener eligibility, and reopening behavior.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 7de5f

The drawer’s focus changes are mergeable after normal checks; no actionable focus regression is established.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue #25570 requires focus to return to the opener after drawer dismissal when focus would otherwise be lost, while preserving deliberate focus moves. AgentDashboardDrawer.tsx captures the opener o…
Out of Scope Changes check ✅ Passed The drawer implementation and component and Electron tests all support issue #25570. The changes stay within renderer focus handling and do not introduce unrelated shared Sheet, store, routing, or vis…
Title check ✅ Passed The title clearly and concisely describes the main change: restoring focus when the Agents drawer closes.
Description check ✅ Passed The description covers the required sections and explains the user-facing change, implementation, linked issue, visual proof, tests, review, and compatibility limits. It also explains why the full che…
  • Fix all pre-merge checks with AI
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Drawer focus capture/restore (AgentDashboardDrawer.tsx) — a useLayoutEffect records the focused opener (and the sheet-content element) on each committed open transition, and a new onCloseAutoFocus handler restores it after Escape/Close/board-close while declining stale callbacks, intentional handoffs, and unavailable openers.
  • Focus-handoff paths — outside dismissal, successful agent reveal, and switch-to-popout now mark the close as a handoff so restoration never steals focus from a destination the user chose; revealDashboardAgent returns a boolean to distinguish a successful reveal from a gone workspace.
  • Tests — 18 component cases against the real Sheet and outside-dismiss hook, plus three real-Electron scenarios covering Escape/Close, outside dismissal/agent reveal, and reopening during the exit animation.

I read the full diff, the surrounding drawer/sidebar/hook code, and the Radix DialogContentNonModal/FocusScope source to confirm the non-modal close still fires onUnmountAutoFocus on the content element. The changed code passes pnpm tc:web and check:code-quality:changed (0 findings), and the new and neighbouring unit suites pass. I also stubbed canReturnFocus to always return true: the hidden and css-hidden cases fail, so the helper is genuinely exercised rather than tautological.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@nwparker

Copy link
Copy Markdown
Contributor

Thanks so much @kambarakun for tracking down the missing focus return and for the thorough Electron validation! We've landed a slightly trimmed version of your fix in #34398 (same approach, a little less code). Your authorship is preserved on the commit. Closing this one in favor of that PR.

@nwparker nwparker closed this Oct 27, 2026
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.

[Bug]: Closing the Agents drawer drops keyboard focus to <body> instead of returning it to the opener

2 participants