import { Send, Image, Sparkles } from 'lucide-react'; import ImagePreview from…
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
import { Send, Image, Sparkles } from 'lucide-react'; import ImagePreview from './ImagePreview';
export default function ChatInput({ input, setInput, imagePreview, handleSendMessage, handleFileSelect, handleRemoveImage, isLoading, fileInputRef }) { return ( {imagePreview && ( )}
<div className="flex items-center gap-2 rounded-full shadow-sm border-2 border-zinc-900 px-3 py-1 focus-within:border-teal-700 transition-all duration-300">
<button
onClick={() => fileInputRef.current?.click()}
className="p-2 text-gray-500 hover:text-cyan-400 hover:bg-slate-900 rounded-full transition-colors"
disabled={isLoading}
>
<Image size={18} strokeWidth={2} />
<input
type="file"
ref={fileInputRef}
onChange={handleFileSelect}
accept="image/*"
className="hidden"
disabled={isLoading}
/>
</button>
<div className="flex-1 relative">
<input
type="text"
value={input}
onChange={(e) => setInput(e.target.value)}
placeholder="Send a message..."
className="w-full py-2 px-3 bg-transparent border-none focus:outline-none text-white placeholder-zinc-500"
onKeyPress={(e) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
handleSendMessage();
}
}}
disabled={isLoading}
/>
</div>
<button
onClick={handleSendMessage}
disabled={isLoading || (!input.trim() && !imagePreview)}
className={`p-2.5 rounded-full flex items-center justify-center transition-all duration-300 ${
isLoading || (!input.trim() && !imagePreview)
? 'bg-zinc-900 text-gray-600 cursor-not-allowed'
: 'bg-gradient-to-r from-cyan-800 to-teal-900 hover:from-cyan-700 hover:to-teal-800 text-cyan-100 hover:shadow-md'
}`}
>
{isLoading ? (
<div className="h-5 w-5 rounded-full border-2 border-t-transparent border-cyan-300 animate-spin"></div>
) : (
<Send size={18} strokeWidth={2} />
)}
</button>
</div>
<div className="flex justify-center mt-2">
<div className="text-xs text-zinc-600 flex items-center gap-1">
<Sparkles size={10} className="text-cyan-600" />
<span>Press Enter to send</span>
</div>
</div>
</div>
</div>
); } the input height should be dynamic
To make the input height dynamic (i.e., grow as the user types more lines), you need to replace the single-line <input> with a multiline <textarea> and adjust its height automatically based on the content.
Here's how you can update your component:
<input> with a <textarea>.ref to access the textarea DOM node.ChatInput component with dynamic height textarea:import { useRef, useEffect } from 'react';
import { Send, Image, Sparkles } from 'lucide-react';
import ImagePreview from './ImagePreview';
export default function ChatInput({
input,
setInput,
imagePreview,
handleSendMessage,
handleFileSelect,
handleRemoveImage,
isLoading,
fileInputRef
}) {
const textareaRef = useRef(null);
// Adjust textarea height based on content
useEffect(() => {
if (textareaRef.current) {
textareaRef.current.style.height = 'auto'; // reset height
textareaRef.current.style.height = textareaRef.current.scrollHeight + 'px'; // set to scrollHeight
}
}, [input]);
return (
<div className="p-4 border-t border-zinc-900 bg-black backdrop-blur-sm shadow-md">
<div className="max-w-4xl mx-auto">
{imagePreview && (
<ImagePreview
imagePreview={imagePreview}
handleRemoveImage={handleRemoveImage}
/>
)}
<div className="flex items-center gap-2 rounded-full shadow-sm border-2 border-zinc-900 px-3 py-1 focus-within:border-teal-700 transition-all duration-300">
<button
onClick={() => fileInputRef.current?.click()}
className="p-2 text-gray-500 hover:text-cyan-400 hover:bg-slate-900 rounded-full transition-colors"
disabled={isLoading}
>
<Image size={18} strokeWidth={2} />
<input
type="file"
ref={fileInputRef}
onChange={handleFileSelect}
accept="image/*"
className="hidden"
disabled={isLoading}
/>
</button>
<div className="flex-1 relative">
<textarea
ref={textareaRef}
value={input}
onChange={(e) => setInput(e.target.value)}
placeholder="Send a message..."
className="w-full py-2 px-3 bg-transparent border-none focus:outline-none text-white placeholder-zinc-500 resize-none overflow-hidden"
onKeyDown={(e) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
handleSendMessage();
}
}}
disabled={isLoading}
rows={1}
/>
</div>
<button
onClick={handleSendMessage}
disabled={isLoading || (!input.trim() && !imagePreview)}
className={`p-2.5 rounded-full flex items-center justify-center transition-all duration-300 ${
isLoading || (!input.trim() && !imagePreview)
? 'bg-zinc-900 text-gray-600 cursor-not-allowed'
: 'bg-gradient-to-r from-cyan-800 to-teal-900 hover:from-cyan-700 hover:to-teal-800 text-cyan-100 hover:shadow-md'
}`}
>
{isLoading ? (
<div className="h-5 w-5 rounded-full border-2 border-t-transparent border-cyan-300 animate-spin"></div>
) : (
<Send size={18} strokeWidth={2} />
)}
</button>
</div>
<div className="flex justify-center mt-2">
<div className="text-xs text-zinc-600 flex items-center gap-1">
<Sparkles size={10} className="text-cyan-600" />
<span>Press Enter to send</span>
</div>
</div>
</div>
</div>
);
}
<input> to <textarea> with rows={1} to start small.resize-none and overflow-hidden to prevent manual resizing and hide scrollbars.useEffect hook to update the height of the textarea whenever input changes:
'auto' to shrink if text is deleted.scrollHeight to fit all content.onKeyPress to onKeyDown because onKeyPress is deprecated and onKeyDown is more reliable for catching Enter key.This will make the textarea grow vertically as the user types more lines, providing a better UX for multiline input.