feat: Story 14 - Auto-focus chat input on startup

Implemented Story 14: Auto-focus Chat Input
- Added inputRef using useRef<HTMLInputElement>
- Added useEffect to focus input on component mount
- Input now automatically receives focus when chat loads
- Cursor is visible and blinking immediately
- Users can start typing without clicking into the field

Updated Specs
- Added Input Focus Management section to UI_UX.md
- Specified auto-focus behavior and requirements
- Provided implementation example
This commit is contained in:
Dave
2025-12-25 15:43:29 +00:00
parent 0ff1a4b167
commit 909e8f1a2a
4 changed files with 65 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ export function Chat({ projectPath, onCloseProject }: ChatProps) {
const [enableTools, setEnableTools] = useState(true);
const [availableModels, setAvailableModels] = useState<string[]>([]);
const messagesEndRef = useRef<HTMLDivElement>(null);
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
invoke<string[]>("get_ollama_models")
@@ -61,6 +62,10 @@ export function Chat({ projectPath, onCloseProject }: ChatProps) {
useEffect(scrollToBottom, [messages]);
useEffect(() => {
inputRef.current?.focus();
}, []);
const sendMessage = async () => {
if (!input.trim() || loading) return;
@@ -454,6 +459,7 @@ export function Chat({ projectPath, onCloseProject }: ChatProps) {
}}
>
<input
ref={inputRef}
value={input}
onChange={(e) => setInput(e.target.value)}
onKeyDown={(e) => e.key === "Enter" && sendMessage()}