Allows a user to send a message with file attachments to a large language model.
It includes a textarea, file upload capabilities, a submit button, and a
dropdown for selecting the model.
The PromptInput component allows a user to send a message with file
attachments to a large language model. It includes a textarea, file upload
capabilities, a submit button, and a dropdown for selecting the model.
See scripts/prompt-input.tsx for this example.
Installation
npx ai-elements@latest add prompt-input
Usage with AI SDK
Build a fully functional chat app using PromptInput,
Conversation with a model picker:
// Simple string tooltip
<PromptInputButton tooltip="Search the web">
<GlobeIcon size={16} />
</PromptInputButton>
// Tooltip with keyboard shortcut hint
<PromptInputButton tooltip={{ content: "Search", shortcut: "⌘K" }}>
<GlobeIcon size={16} />
</PromptInputButton>
// Tooltip with custom position
<PromptInputButton tooltip={{ content: "Search", side: "bottom" }}>
<GlobeIcon size={16} />
</PromptInputButton>
<PromptInputSubmit />
Prop
Type
Default
Description
status
ChatStatus
-
Current chat status to determine button icon (submitted, streaming, error).
...props
React.ComponentProps<typeof Button>
-
Any other props are spread to the underlying shadcn/ui Button component.
<PromptInputSelect />
Prop
Type
Default
Description
...props
React.ComponentProps<typeof Select>
-
Any other props are spread to the underlying Select component.
<PromptInputSelectTrigger />
Prop
Type
Default
Description
...props
React.ComponentProps<typeof SelectTrigger>
-
Any other props are spread to the underlying SelectTrigger component.
<PromptInputSelectContent />
Prop
Type
Default
Description
...props
React.ComponentProps<typeof SelectContent>
-
Any other props are spread to the underlying SelectContent component.
<PromptInputSelectItem />
Prop
Type
Default
Description
...props
React.ComponentProps<typeof SelectItem>
-
Any other props are spread to the underlying SelectItem component.
<PromptInputSelectValue />
Prop
Type
Default
Description
...props
React.ComponentProps<typeof SelectValue>
-
Any other props are spread to the underlying SelectValue component.
<PromptInputBody />
Prop
Type
Default
Description
...props
React.HTMLAttributes<HTMLDivElement>
-
Any other props are spread to the body div.
Attachments
Attachment components have been moved to a separate module. See the
Attachment component documentation for details on
<Attachments />, <Attachment />, <AttachmentPreview />,
<AttachmentInfo />, and <AttachmentRemove />.
<PromptInputActionMenu />
Prop
Type
Default
Description
...props
React.ComponentProps<typeof DropdownMenu>
-
Any other props are spread to the underlying DropdownMenu component.
<PromptInputActionMenuTrigger />
Prop
Type
Default
Description
...props
React.ComponentProps<typeof Button>
-
Any other props are spread to the underlying Button component.
<PromptInputActionMenuContent />
Prop
Type
Default
Description
...props
React.ComponentProps<typeof DropdownMenuContent>
-
Any other props are spread to the underlying DropdownMenuContent component.
<PromptInputActionMenuItem />
Prop
Type
Default
Description
...props
React.ComponentProps<typeof DropdownMenuItem>
-
Any other props are spread to the underlying DropdownMenuItem component.
<PromptInputActionAddAttachments />
Prop
Type
Default
Description
label
string
-
Label for the menu item.
...props
React.ComponentProps<typeof DropdownMenuItem>
-
Any other props are spread to the underlying DropdownMenuItem component.
<PromptInputProvider />
Prop
Type
Default
Description
initialInput
string
-
Initial text input value.
children
React.ReactNode
-
Child components that will have access to the provider context.
Optional global provider that lifts PromptInput state outside of PromptInput.
When used, it allows you to access and control the input state from anywhere
within the provider tree. If not used, PromptInput stays fully self-managed.
const attachments = usePromptInputAttachments();
// Available methods:
attachments.files; // Array of current attachments
attachments.add(files); // Add new files
attachments.remove(id); // Remove an attachment by ID
attachments.clear(); // Clear all attachments
attachments.openFileDialog(); // Open file selection dialog
usePromptInputController
Access the full PromptInput controller from a PromptInputProvider. Only
available when using the provider.
const controller = usePromptInputController();
// Available methods:
controller.textInput.value; // Current text input value
controller.textInput.setInput(value); // Set text input value
controller.textInput.clear(); // Clear text input
controller.attachments; // Same as usePromptInputAttachments
useProviderAttachments
Access attachments context from a PromptInputProvider. Only available when using
the provider.
const sources = usePromptInputReferencedSources();
// Available methods:
sources.sources; // Array of current referenced sources
sources.add(sources); // Add new source(s)
sources.remove(id); // Remove a source by ID
sources.clear(); // Clear all sources