The MessageInput component is a rich textarea designed for AI chat interfaces. It supports auto-resizing, file attachments, and voice input.
Basic Usage
import { MessageInput } from "@/components/ui/message-input"
export function BasicMessageInput() {
return (
<MessageInput
value={input}
onChange={handleInputChange}
isGenerating={false}
/>
)
}
With Interrupt Behavior
When enableInterrupt is true and isGenerating is true, pressing Enter once will prompt the user to press Enter again to interrupt the generation. This is useful for preventing accidental interruptions.
export function MessageInputWithInterrupt() {
return (
<MessageInput
value={input}
onChange={handleInputChange}
isGenerating={isGenerating}
stop={handleStop}
enableInterrupt={true}
/>
)
}
With File Attachments
To enable file attachments and drag-and-drop support, set allowAttachments to true and manage the files state.
import { MessageInput } from "@/components/ui/message-input"
export function MessageInputWithAttachments() {
const [files, setFiles] = useState<File[] | null>(null)
return (
<MessageInput
value={input}
onChange={handleInputChange}
isGenerating={false}
allowAttachments
files={files}
setFiles={setFiles}
/>
)
}
Voice Input
Providing the transcribeAudio prop will automatically display the voice input button. This function handles the conversion of audio blobs to text.
<MessageInput
value={input}
onChange={handleInputChange}
isGenerating={false}
transcribeAudio={transcribeAudio}
/>
import { MessageInput } from "@/components/ui/message-input"
export function BasicMessageInput() {
return (
<MessageInput
value={input}
onChange={handleInputChange}
isGenerating={false}
/>
)
}