切换到会话时输入框自动聚焦

匹配主流IM客户端的习惯——切进一个聊天窗口应该能直接开始打字,不需要先手动
点一下输入框。只在topicId变化时聚焦一次,不依赖messages(否则每来一条新
消息就会把正在做其他操作的用户的焦点抢走)。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Your Name
2026-09-16 22:25:38 +08:00
co-authored by Claude Sonnet 5
parent 3df61e9e59
commit f570483b62
@@ -267,6 +267,15 @@ export function ConversationView() {
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [topicId]); }, [topicId]);
// Switching into a chat window should let the user start typing immediately, not require an extra
// click into the input first -- matches every mainstream IM client. Deliberately NOT keyed on
// `messages` (would re-steal focus away from whatever the user is doing every time a new message
// arrives while they're already composing) -- only the initial switch itself should grab focus.
useEffect(() => {
if (!topicId) return;
textareaRef.current?.focus();
}, [topicId]);
// Someone else dissolving the group currently open here (or this account being removed from it) // Someone else dissolving the group currently open here (or this account being removed from it)
// fires the SDK's `onDeleteTopic`, not `onData`/`onPres` -- those only invalidate this screen's // fires the SDK's `onDeleteTopic`, not `onData`/`onPres` -- those only invalidate this screen's
// cached snapshots for re-render, they don't tell it the topic itself is gone. Left unhandled, the // cached snapshots for re-render, they don't tell it the topic itself is gone. Left unhandled, the