Add autofocus on chat
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user