import { useState, useRef, useEffect } from 'react'; export default function ChatInput({ onSubmit, loading }) { const [value, setValue] = useState(''); const textareaRef = useRef(null); useEffect(() => { if (textareaRef.current) { textareaRef.current.style.height = 'auto'; textareaRef.current.style.height = `${Math.min(textareaRef.current.scrollHeight, 160)}px`; } }, [value]); const handleKeyDown = (e) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); submit(); } }; const submit = () => { const trimmed = value.trim(); if (!trimmed || loading) return; onSubmit(trimmed); setValue(''); }; return (
Enter to send ยท Shift+Enter for new line