You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(agent-dashboard): restore focus to the opener when the drawer closes - #34398
When you opened the Agents side panel and then closed it with Escape or the Close button, your keyboard focus "fell off" the app. Nothing was selected, so typing went nowhere until you clicked something. Now the app remembers what you were using when you opened the panel, like the sidebar button or a terminal, and puts you back there when you close it. If you closed it by clicking somewhere else, or by jumping to an agent, it leaves you where you went.
What Changed
Before: closing the in-window Agents drawer with Escape or Close left document.activeElement on <body>.
After: focus returns to the element that opened the drawer.
Mechanism (AgentDashboardDrawer.tsx):
A layout effect records the focused element on each open transition. If focus is already inside the sheet, it keeps the earlier opener, which covers reopening during the exit animation.
onCloseAutoFocus focuses that opener only when focus would otherwise be lost (active element is body) and the close was not a focus handoff.
Three kinds of close count as handoffs and leave focus where it went: outside pointer dismissal, a successful agent reveal, and switching to the pop-out. A failed reveal still restores focus.
New AgentDashboardDrawer.focus.test.tsx has 9 cases. It uses the real Radix Sheet and the real outside-dismiss hook.
Why
The drawer is opened from the store and has no Radix DialogTrigger. On close, Radix's non-modal close autofocus only focuses triggerRef, which is null here, and then calls preventDefault(). That also blocks FocusScope's own restore of the previously focused element, so focus lands on <body>. Restoring focus on every close would steal focus from an outside click or a revealed agent pane, so the drawer now tells the two kinds of close apart.
The fix changes where keyboard focus goes and has no visual or styling change. @kambarakun captured these screenshots in #25640 with the same sidebar → search → Escape sequence in a disposable Electron fixture. The focus outline exists only in the test. Before, focus is on BODY. After, the sidebar button has focus again.
Before
After
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Reproduced in a unit test. Run against main's drawer source, the new focus test fails 5 of 9 cases with "expected <body> to be <button>": Escape, Close, store dismissal followed by a new opener, reopening during the exit animation, and a failed reveal. All 9 pass with this change.
Real Electron, headless with ORCA_BACKGROUND_LAUNCH=1, using the contributor's e2e scenarios from a scratch copy. On main, 2 of 3 fail (no focus after Escape/Close, and after reopening during the exit animation). With this change, 3 of 3 pass. The e2e spec is not checked in.
5 extra probes also pass on this branch: no focus steal, handoff flag resets, opener removed from the DOM, nothing focused at open, and reopen after pop-out. The neighbouring dashboard and outside-dismiss suites pass too.
oxlint, oxfmt --check, the anti-slop, code-quality and ast-grep gates, and check-changed-code-quality are clean on the touched files.
Platform: macOS. The change uses only DOM focus, so nothing is platform-specific.
Review
Root cause confirmed against the installed Radix dialog and focus-scope sources.
It also removes the stale-callback content tracking. Radix fires close autofocus only after the content unmounts, so the body check already covers a reopen during the exit animation.
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
Renderer focus policy only: no IPC, no persisted state, no new global listeners, no styling change.
Local, SSH and folder workspaces are unaffected, and so are mixed client/server versions.
Mobile has no in-window drawer, so it is unaffected.
Original fix by @kambarakun in #25640. Authorship is preserved on the commit.
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)
The store-driven Agents drawer has no Radix trigger, so dismissing it with
Escape or the close button dropped focus to document.body. Capture the
focused element on each open transition and return focus to it on close,
unless focus already moved elsewhere or the close hands focus off (outside
pointer dismissal, agent reveal, switching to the pop-out).
Co-authored-by: Neil <[email protected]>
The drawer records the element focused when it opens. On close, it restores focus to that element only when focus is absent or on body and no focus handoff occurred. Agent reveal, pop-out, and outside dismissal use handoff behavior. Tests cover focus restoration, handoffs, reopening, and stale close callbacks.
Priority: Normal
Severity of issue fixed: Medium
Merge Risk: Low · up to 2b24b
In two dismissal cases, keyboard focus can end up on the page instead of returning to the drawer opener. These bounded issues should be fixed or explicitly accepted before merging.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surv…
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Title check
The title names the main change: focus is restored to the opener when the Agents drawer closes. It also names the scope, agent-dashboard, and uses the fix type. The title matches the changeset, which …
Description check
The description follows the repository template and fills in the main sections. ELI5, What Changed, Why, Linked Issue (Fixes #25570), Visual Proof, Testing, Review, Agent skill upstream boundary, Note…
Linked Issues check
Directly linked issue #25570 requires that closing the in-window Agents drawer while focus is inside it (Escape, close button, or a card action) returns focus to the opener if the opener still exists …
Out of Scope Changes check
The PR changes two files only, matching the summary: AgentDashboardDrawer.tsx (+50/-10) and new AgentDashboardDrawer.focus.test.tsx (+192). Every production change serves focus return on drawer close:…
Full details: Title check
Explanation
The title names the main change: focus is restored to the opener when the Agents drawer closes. It also names the scope, agent-dashboard, and uses the fix type. The title matches the changeset, which adds focus restoration to AgentDashboardDrawer.tsx and a focus test file.
Full details: Description check
Explanation
The description follows the repository template and fills in the main sections. ELI5, What Changed, Why, Linked Issue (Fixes #25570), Visual Proof, Testing, Review, Agent skill upstream boundary, Notes, and Checklist are all present with substantive content. The AI Disclosure section is left empty, which the template allows for internal contributors. The description does not show whether the author is a stablyai team member, so that section needs a check. The Visual Proof section links screenshots from another PR (#25640) rather than attaching screenshots to this PR. The template asks for before and after visuals for UI behavior changes, so the reviewer should confirm those images are accessible from this PR.
Full details: Linked Issues check
Explanation
Directly linked issue #25570 requires that closing the in-window Agents drawer while focus is inside it (Escape, close button, or a card action) returns focus to the opener if the opener still exists and the user has not moved focus elsewhere. Reviewed head AgentDashboardDrawer.tsx: (1) A useLayoutEffect on each open transition stores document.activeElement as focusReturnRef.opener when it is an HTMLElement outside the sheet and not body. A reopen while focus is already inside the sheet keeps the earlier opener. (2) handleCloseAutoFocus calls preventDefault and focuses the stored opener when handoff is false and document.activeElement is null or body. Radix unmount leaves focus on body, so this covers Escape (close()), the close button (onClose=close), and a failed agent reveal (onClose). (3) Outside-pointer dismissal (useWorkspaceKanbanOutsideDismiss via closeForFocusHandoff), a successful reveal (revealDashboardAgent returns true, then onFocusHandoff), and pop-out switching (onFocusHandoff) set handoff=true, so focus stays where the user moved it. This matches the issue's terminal-click exception. The reset of handoff on each open prevents stale flags. Store-driven closes with focus outside the sheet do not move focus, because activeElement is not body. The issue's card-action case maps to the reveal path, which is handled. Test file AgentDashboardDrawer.focus.test.tsx covers Escape, the close button, store dismissal with outside focus, outside pointerdown handoff, next-opener capture, stale close callback, reveal success and failure, and pop-out. The PR reports that 5 of 9 cases fail on main. Limits: the base-to-head production diff could not be read, so I checked head content and the supplied +50/-10 summary. I did not run the tests. The e2e spec is not checked in. The issue's suggested check for body or inside-sheet focus is narrowed to body only. This is equivalent in practice, because focus is already on body after unmount.
Full details: Out of Scope Changes check
Explanation
The PR changes two files only, matching the summary: AgentDashboardDrawer.tsx (+50/-10) and new AgentDashboardDrawer.focus.test.tsx (+192). Every production change serves focus return on drawer close: the opener-capture layout effect, the handoff flag and closeForFocusHandoff wrapper, the onCloseAutoFocus handler, and the handoff callback passed to AgentDashboardDrawerBody for reveal and pop-out. The handoff call on pop-out and the reveal branch change only focus behavior. The test file exercises only the drawer's focus behavior with mocked dependencies. No IPC, persisted state, styling, or unrelated component changes appear in the PR summary. The PR description's screenshots and the attribution to #25640 are documentation, not code, and do not affect scope.
Full details: Docstring Coverage
Explanation
Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 2 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches: 💡 1
📝 Generate docstrings: 💡
Commit to this branch
Create a new PR
Autofix · 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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
set -o pipefail
printf'%s\n''--- board callback call site ---'
nl -ba src/renderer/src/components/dashboard-popout/AgentKanbanBoard.tsx | sed -n '270,310p'printf'%s\n''--- card reveal data flow ---'
rg -n -F --glob '*.{ts,tsx}' -e 'leafId:' -e 'leafId' src/renderer/src/components/dashboard src/renderer/src/components/dashboard-popout src/shared/dashboard-snapshot.ts | sed -n '1,220p'printf'%s\n''--- snapshot producer definitions ---'
rg -n -F --glob '*.{ts,tsx}' -e 'DashboardSnapshot' -e 'AgentCard' -e 'cards:' src/renderer/src/components/dashboard src/shared | sed -n '1,220p'
Repository: stablyai/orca
Length of output: 34491
Do not assume every successful reveal hands off focus.
When leafId is null, revealDashboardAgent returns true after workspace activation, but activateTabAndFocusPane returns before scheduling a pane-focus request. Local workspaces have no owner focus handoff. The drawer then marks the handoff as complete and suppresses opener restoration.
Treat the reveal as a focus handoff only when a replacement target receives focus, or restore opener focus when the null-leaf reveal leaves focus on body.
Outside-pointer dismissal skips opener return when the click lands on a nonfocusable area.
closeForFocusHandoff sets handoff = true for every outside-pointer dismissal. When the clicked target cannot take focus, focus moves to body and nothing replaces it. handleCloseAutoFocus then skips the opener, so focus stays on body. The issue asks for focus to return to the opener unless the user moved focus elsewhere. A click on a nonfocusable area does not move focus to a control.
Pass close to the outside-dismiss hook instead. A focusable target keeps focus, so the existing body check already prevents a restore there.
IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
When you opened the Agents side panel and then closed it with Escape or the Close button, your keyboard focus "fell off" the app. Nothing was selected, so typing went nowhere until you clicked something. Now the app remembers what you were using when you opened the panel, like the sidebar button or a terminal, and puts you back there when you close it. If you closed it by clicking somewhere else, or by jumping to an agent, it leaves you where you went.
What Changed
document.activeElementon<body>.AgentDashboardDrawer.tsx):onCloseAutoFocusfocuses that opener only when focus would otherwise be lost (active element isbody) and the close was not a focus handoff.AgentDashboardDrawer.focus.test.tsxhas 9 cases. It uses the real Radix Sheet and the real outside-dismiss hook.Why
The drawer is opened from the store and has no Radix
DialogTrigger. On close, Radix's non-modal close autofocus only focusestriggerRef, which is null here, and then callspreventDefault(). That also blocks FocusScope's own restore of the previously focused element, so focus lands on<body>. Restoring focus on every close would steal focus from an outside click or a revealed agent pane, so the drawer now tells the two kinds of close apart.Linked Issue
Fixes #25570
Visual Proof
The fix changes where keyboard focus goes and has no visual or styling change. @kambarakun captured these screenshots in #25640 with the same sidebar → search → Escape sequence in a disposable Electron fixture. The focus outline exists only in the test. Before, focus is on
BODY. After, the sidebar button has focus again.Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Reproduced in a unit test. Run against main's drawer source, the new focus test fails 5 of 9 cases with "expected
<body>to be<button>": Escape, Close, store dismissal followed by a new opener, reopening during the exit animation, and a failed reveal. All 9 pass with this change.Real Electron, headless with
ORCA_BACKGROUND_LAUNCH=1, using the contributor's e2e scenarios from a scratch copy. On main, 2 of 3 fail (no focus after Escape/Close, and after reopening during the exit animation). With this change, 3 of 3 pass. The e2e spec is not checked in.5 extra probes also pass on this branch: no focus steal, handoff flag resets, opener removed from the DOM, nothing focused at open, and reopen after pop-out. The neighbouring dashboard and outside-dismiss suites pass too.
oxlint,oxfmt --check, the anti-slop, code-quality and ast-grep gates, andcheck-changed-code-qualityare clean on the touched files.Platform: macOS. The change uses only DOM focus, so nothing is platform-specific.
Review
canReturnFocusancestor walk. Chromium'sfocus()already does nothing on disconnected, disabled, hidden or inert elements.bodycheck already covers a reopen during the exit animation.Agent skill upstream boundary
Notes
Original fix by @kambarakun in #25640. Authorship is preserved on the commit.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)