Skip to content

fix(native-chat): return focus to the composer after picking a model or effort - #26574

Merged
brennanb2025 merged 1 commit into
stablyai:mainfrom
AmoabaKelvin:return-focus-after-picker-choice
Oct 8, 2026
Merged

brennanb2025 merged 1 commit into
stablyai:mainfrom
AmoabaKelvin:return-focus-after-picker-choice

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

ELI5

In the chat box, picking a model or an effort level used to leave your cursor stuck on the little button you just clicked, so you had to click back into the text box before you could type. Now your cursor goes straight back to the text box.

What Changed

Before: you click the "Opus" pill, pick a model, the list closes — and the pill keeps the keyboard focus, with its tooltip hanging around. Typing does nothing until you click into the message box. Same for the effort/options pill beside it.

After: picking a value closes the picker and puts the cursor back in the message box, ready to type. Dismissing the picker without choosing anything — Escape or Tab — still leaves focus on the pill, unchanged.

Mechanism: both pills are Radix surfaces, and Radix deliberately restores focus to the trigger when a menu or popover closes, so the user keeps their place in the document. The documented way to override that is onCloseAutoFocus: cancel the event, then move focus yourself. The pills don't own the message box, so the composer now passes down the same focusComposer callback the queued-send dialog already uses.

Three surfaces needed the handler, because the model pill renders one of two different primitives depending on the agent: a searchable popover when the agent lists real model choices, a plain menu when it only offers a toggle or "Choose in agent picker…". The effort/options pill is the third.

A small hook, useNativeChatPickerFocusReturn, carries the one piece of state the handler needs: whether the surface closed because you picked something.

Why

Choosing a model mid-conversation is something you do while writing a message. Losing the cursor in the middle of that is a small tax paid every single time.

Why distinguish a pick from a dismissal, instead of always returning to the message box? Tab. The searchable model picker closes on Tab so focus isn't trapped in its search field, and the message box sits before the pills in the DOM. If Tab also redirected to the message box, pressing Tab would move focus backwards. Escape returning to the trigger is also what the ARIA menu-button pattern calls for, and what the searchable picker already did.

Why not just event.preventDefault() and stop? That cancels Radix's focus restore without supplying a replacement, so focus falls to <body> and keyboard users lose their place entirely.

Why thread a callback instead of reaching for the textarea from the picker? The composer already owns textareaRef and already hands this exact callback to NativeChatQueueSendConfirmDialog. Reusing it keeps one definition of "give focus back" for the pane.

Two cases are deliberately left alone: the toggle switch rows keep their menu open, so they shouldn't move focus at all; and "Choose in agent picker…" hands you off to the agent's own picker, which owns what happens next.

Linked Issue

No pre-existing issue — reported directly.

Visual Proof

Before:
image

After:

CleanShot.2026-10-08.at.12.57.44.PM.mp4

Testing

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

NativeChatSessionOptionPickers.focus-return.test.tsx renders the real Radix primitives rather than mocks — the existing pickers test stubs them out, so it structurally cannot observe focus restoration. It asserts document.activeElement across four cases: picking an effort, picking a model, dismissing with Escape, and toggling a switch that keeps its menu open.

Confirmed as a real repro: with the production change reverted and the test kept, the two focus-return cases fail; with it applied, all four pass, including the Escape case that must not change.

Review

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

  • Cross-platform: no platform-dependent code. No keyboard accelerators, no paths, no shell.
  • SSH / remote: nothing touches the execution host. Focus moves entirely within the renderer, after the option write has already been dispatched, so latency on the write can't strand the cursor.
  • Mobile: unaffected. The phone's session-option rows are React Native Pressables with no Radix and no focus restoration to undo.
  • Backwards compatibility: no wire change, no RPC change, no persisted state.
  • Performance: the callback is memoized so the memoized pickers keep their identity; one useRef per picker.
  • Security: none.
  • Localization: no new user-facing strings.

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)

Radix restores focus to the trigger on close, so the model and effort
pills kept it. Escape and Tab still land there; only a choice moves on.
@AmoabaKelvin
AmoabaKelvin force-pushed the return-focus-after-picker-choice branch from 57624ae to e0f214a Compare October 8, 2026 12:51
@AmoabaKelvin
AmoabaKelvin marked this pull request as ready for review October 8, 2026 12:58
@coderabbitai

coderabbitai Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: 54b3b772-591d-40af-b80a-706596c1b532
📥 Commits

Reviewing files that changed from the base of the PR and between e3639ef and e0f214a.

📒 Files selected for processing (6)
  • src/renderer/src/components/native-chat/NativeChatComposerActions.tsx
  • src/renderer/src/components/native-chat/NativeChatComposerField.tsx
  • src/renderer/src/components/native-chat/NativeChatModelCombobox.tsx
  • src/renderer/src/components/native-chat/NativeChatSessionOptionPickers.focus-return.test.tsx
  • src/renderer/src/components/native-chat/NativeChatSessionOptionPickers.tsx
  • src/renderer/src/components/native-chat/native-chat-picker-focus-return.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 composer now provides a memoized textarea focus callback to its actions and queue-send confirmation dialog. Native chat model and session option pickers use a focus-return hook to restore composer focus after a selection closes a menu. Tests cover focus after effort and model selections, menu dismissal, and Fast mode toggling.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to e0f21

The reviewed picker focus behavior has no identified issue requiring a fix before merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: returning focus to the composer after selecting a model or effort option.
Description check ✅ Passed The description is detailed and covers the user impact, implementation, rationale, testing, visual proof, compatibility considerations, and checklist. The Linked Issue section does not provide an issu…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • 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.

@brennanb2025
brennanb2025 merged commit 6ceb423 into stablyai:main Oct 8, 2026
56 of 69 checks passed
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.

2 participants