Add autofocus on chat

This commit is contained in:
Samuele E. Locatelli
2025-08-22 17:29:49 +00:00
parent eeb9df4ccf
commit fb54ebf116
+11 -1
View File
@@ -1,7 +1,16 @@
import React, { useState } from "react";
// src/ChatInput.jsx
import React, { useState, useRef, useEffect } from "react";
export default function ChatInput({ onSend, loading }) {
const [value, setValue] = useState("");
const textareaRef = useRef(null);
// Autofocus on mount and after each retrieval
useEffect(() => {
if (!loading && textareaRef.current) {
textareaRef.current.focus();
}
}, [loading]);
const handleKeyDown = (e) => {
if (e.key === "Enter" && !e.shiftKey) {
@@ -16,6 +25,7 @@ export default function ChatInput({ onSend, loading }) {
return (
<div className="p-2 border-top bg-white">
<textarea
ref={textareaRef}
className="form-control"
rows={3}
value={value}