Repository navigation
fix(native-chat): return focus to the composer after picking a model or effort - #26574
Conversation
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.
57624ae to
e0f214a
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (6)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe 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 The reviewed picker focus behavior has no identified issue requiring a fix before merge. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
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 samefocusComposercallback 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
textareaRefand already hands this exact callback toNativeChatQueueSendConfirmDialog. 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:

After:
CleanShot.2026-10-08.at.12.57.44.PM.mp4
Testing
NativeChatSessionOptionPickers.focus-return.test.tsxrenders the real Radix primitives rather than mocks — the existing pickers test stubs them out, so it structurally cannot observe focus restoration. It assertsdocument.activeElementacross 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
Notes
Pressables with no Radix and no focus restoration to undo.useRefper picker.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)