import React, { useRef, useEffect } from 'react'; import './MessageInput.css'; /** * MessageInput — text input + send button for the chat. * * - Large input field (min 56px height) * - Prominent send button * - Submits on Enter (Shift+Enter adds a newline) * - Disabled while isTyping * - Auto-focused on mount */ function MessageInput({ onSend, isTyping }) { const inputRef = useRef(null); // Auto-focus on mount useEffect(() => { if (inputRef.current) { inputRef.current.focus(); } }, []); // Re-focus after response arrives useEffect(() => { if (!isTyping && inputRef.current) { inputRef.current.focus(); } }, [isTyping]); const handleSend = () => { const text = inputRef.current?.value ?? ''; if (!text.trim() || isTyping) return; onSend(text); if (inputRef.current) { inputRef.current.value = ''; } }; const handleKeyDown = (e) => { // Enter submits; Shift+Enter adds newline (for textarea) if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSend(); } }; return (
); } export default MessageInput;