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:
@@ -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()}
|
||||
|
||||
Reference in New Issue
Block a user