- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Code Block
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Direction
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Kbd
- Label
- Marker
- Menubar
- Message
- Message Scroller
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Questionnaire
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Tooltip
- Trace
- Typography
"use client"
import * as React from "react""use client"
import * as React from "react"
import {
ArrowUpIcon,
ChevronDownIcon,
FileTextIcon,
PlusIcon,
XIcon,
} from "lucide-react"
import {
Attachment,
AttachmentAction,
AttachmentActions,
AttachmentContent,
AttachmentMedia,
AttachmentTitle,
} from "@/components/ui/attachment"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuLabel,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import {
InputGroup,
InputGroupAddon,
InputGroupButton,
InputGroupTextarea,
} from "@/components/ui/input-group"
type AttachmentFile = {
id: string
name: string
}
const providers = [
{
name: "OpenAI",
models: [
{ id: "gpt-5", name: "GPT-5" },
{ id: "gpt-5-mini", name: "GPT-5 mini" },
],
},
{
name: "Anthropic",
models: [
{ id: "claude-sonnet-4-5", name: "Claude Sonnet 4.5" },
{ id: "claude-haiku-4-5", name: "Claude Haiku 4.5" },
],
},
]
const models = providers.flatMap((provider) => provider.models)
const efforts = [
{ id: "low", name: "Low" },
{ id: "medium", name: "Medium" },
{ id: "high", name: "High" },
]
export function PromptInputDemo() {
const [text, setText] = React.useState("")
const [files, setFiles] = React.useState<AttachmentFile[]>([])
const [model, setModel] = React.useState(models[0].id)
const [effort, setEffort] = React.useState(efforts[1].id)
const formRef = React.useRef<HTMLFormElement>(null)
const inputRef = React.useRef<HTMLInputElement>(null)
const currentModel = models.find((item) => item.id === model) ?? models[0]
const currentEffort = efforts.find((item) => item.id === effort) ?? efforts[1]
const canSend = text.trim().length > 0
function onSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault()
if (!canSend) {
return
}
setText("")
setFiles([])
}
function onAttach(event: React.ChangeEvent<HTMLInputElement>) {
const selected = event.target.files
if (!selected) {
return
}
setFiles((current) => [
...current,
...Array.from(selected, (file) => ({
id: crypto.randomUUID(),
name: file.name,
})),
])
event.target.value = ""
}
return (
<div className="mx-auto w-full max-w-lg py-6">
<form ref={formRef} onSubmit={onSubmit}>
<input
ref={inputRef}
type="file"
multiple
className="sr-only"
tabIndex={-1}
onChange={onAttach}
/>
<InputGroup>
{files.length > 0 && (
<InputGroupAddon align="block-start" className="flex-wrap">
{files.map((file) => (
<Attachment key={file.id} size="sm">
<AttachmentMedia>
<FileTextIcon />
</AttachmentMedia>
<AttachmentContent>
<AttachmentTitle>{file.name}</AttachmentTitle>
</AttachmentContent>
<AttachmentActions>
<AttachmentAction
aria-label={`Remove ${file.name}`}
onClick={() =>
setFiles((current) =>
current.filter((item) => item.id !== file.id)
)
}
>
<XIcon />
</AttachmentAction>
</AttachmentActions>
</Attachment>
))}
</InputGroupAddon>
)}
<InputGroupTextarea
value={text}
onChange={(event) => setText(event.target.value)}
placeholder="Ask the agent to change your code..."
onKeyDown={(event) => {
if (event.key === "Enter" && !event.shiftKey) {
event.preventDefault()
formRef.current?.requestSubmit()
}
}}
className="p-3"
/>
<InputGroupAddon align="block-end">
<InputGroupButton
size="icon-sm"
variant="outline"
className="rounded-full"
aria-label="Attach files"
onClick={() => inputRef.current?.click()}
>
<PlusIcon />
</InputGroupButton>
<DropdownMenu>
<DropdownMenuTrigger render={<InputGroupButton size="sm" variant="outline" aria-label={`Model: ${currentModel.name}`} className="ml-auto">{currentModel.name}<ChevronDownIcon /></InputGroupButton>} />
<DropdownMenuContent align="start" className="w-48">
<DropdownMenuRadioGroup value={model} onValueChange={setModel}>
{providers.map((provider, index) => (
<React.Fragment key={provider.name}>
{index > 0 && <DropdownMenuSeparator />}
<DropdownMenuGroup>
<DropdownMenuLabel>{provider.name}</DropdownMenuLabel>
{provider.models.map((item) => (
<DropdownMenuRadioItem
key={item.id}
value={item.id}
closeOnClick
>
{item.name}
</DropdownMenuRadioItem>
))}
</DropdownMenuGroup>
</React.Fragment>
))}
</DropdownMenuRadioGroup>
</DropdownMenuContent>
</DropdownMenu>
<DropdownMenu>
<DropdownMenuTrigger render={<InputGroupButton size="sm" variant="outline" aria-label={`Effort: ${currentEffort.name}`}><span className="text-muted-foreground">Effort</span>{currentEffort.name}<ChevronDownIcon /></InputGroupButton>} />
<DropdownMenuContent align="start" className="w-36">
<DropdownMenuGroup>
<DropdownMenuLabel>Effort</DropdownMenuLabel>
<DropdownMenuRadioGroup
value={effort}
onValueChange={setEffort}
>
{efforts.map((item) => (
<DropdownMenuRadioItem
key={item.id}
value={item.id}
closeOnClick
>
{item.name}
</DropdownMenuRadioItem>
))}
</DropdownMenuRadioGroup>
</DropdownMenuGroup>
</DropdownMenuContent>
</DropdownMenu>
<InputGroupButton
type="submit"
size="icon-sm"
variant="default"
className="rounded-full"
disabled={!canSend}
aria-label="Send"
>
<ArrowUpIcon />
</InputGroupButton>
</InputGroupAddon>
</InputGroup>
</form>
</div>
)
}
Prompt Input is the field the person types into to message the agent. It is an Input Group with a textarea, an attach button, the Model Selector menus and a send button. Attached files show as Attachment chips above the text.
Installation#
Prompt Input is built with the Input Group, Attachment and Dropdown Menu components.
pnpm dlx shadcn@latest add input-group attachment dropdown-menu
Install the required shadcn/ui dependencies:
pnpm dlx shadcn@latest add input-group attachment dropdown-menu
Copy and paste the following code into your project.
"use client"
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Textarea } from "@/components/ui/textarea"
function InputGroup({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="input-group"
role="group"
className={cn(
"group/input-group relative flex h-8 w-full min-w-0 items-center rounded-2xl border border-transparent bg-input/50 transition-[color,box-shadow] duration-200 outline-none in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-3 has-[[data-slot=input-group-control]:focus-visible]:ring-ring/30 has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-3 has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5",
className
)}
{...props}
/>
)
}
const inputGroupAddonVariants = cva(
"flex h-auto cursor-text items-center justify-center gap-2 py-1.5 text-sm font-medium text-muted-foreground select-none group-data-[disabled=true]/input-group:opacity-50 **:data-[slot=kbd]:rounded-2xl **:data-[slot=kbd]:bg-muted-foreground/10 **:data-[slot=kbd]:px-1.5 [&>svg:not([class*='size-'])]:size-4",
{
variants: {
align: {
"inline-start":
"order-first pl-2 has-[>button]:ml-[-0.3rem] has-[>kbd]:ml-[-0.15rem]",
"inline-end":
"order-last pr-2 has-[>button]:mr-[-0.3rem] has-[>kbd]:mr-[-0.15rem]",
"block-start":
"order-first w-full justify-start px-2.5 pt-2 group-has-[>input]/input-group:pt-2 [.border-b]:pb-2",
"block-end":
"order-last w-full justify-start px-2.5 pb-2 group-has-[>input]/input-group:pb-2 [.border-t]:pt-2",
},
},
defaultVariants: {
align: "inline-start",
},
}
)
function InputGroupAddon({
className,
align = "inline-start",
...props
}: React.ComponentProps<"div"> & VariantProps<typeof inputGroupAddonVariants>) {
return (
<div
role="group"
data-slot="input-group-addon"
data-align={align}
className={cn(inputGroupAddonVariants({ align }), className)}
onClick={(e) => {
if ((e.target as HTMLElement).closest("button")) {
return
}
e.currentTarget.parentElement?.querySelector("input")?.focus()
}}
{...props}
/>
)
}
const inputGroupButtonVariants = cva(
"flex items-center gap-2 rounded-2xl text-sm shadow-none",
{
variants: {
size: {
xs: "h-6 gap-1 rounded-xl px-1.5 [&>svg:not([class*='size-'])]:size-3.5",
sm: "",
"icon-xs": "size-6 rounded-xl p-0 has-[>svg]:p-0",
"icon-sm": "size-8 p-0 has-[>svg]:p-0",
},
},
defaultVariants: {
size: "xs",
},
}
)
function InputGroupButton({
className,
type = "button",
variant = "ghost",
size = "xs",
...props
}: Omit<React.ComponentProps<typeof Button>, "size" | "type"> &
VariantProps<typeof inputGroupButtonVariants> & {
type?: "button" | "submit" | "reset"
}) {
return (
<Button
type={type}
data-size={size}
variant={variant}
className={cn(inputGroupButtonVariants({ size }), className)}
{...props}
/>
)
}
function InputGroupText({ className, ...props }: React.ComponentProps<"span">) {
return (
<span
className={cn(
"flex items-center gap-2 text-sm text-muted-foreground [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
className
)}
{...props}
/>
)
}
function InputGroupInput({
className,
...props
}: React.ComponentProps<"input">) {
return (
<Input
data-slot="input-group-control"
className={cn(
"flex-1 rounded-none border-0 bg-transparent shadow-none ring-0 focus-visible:ring-0 aria-invalid:ring-0 dark:bg-transparent",
className
)}
{...props}
/>
)
}
function InputGroupTextarea({
className,
...props
}: React.ComponentProps<"textarea">) {
return (
<Textarea
data-slot="input-group-control"
className={cn(
"flex-1 resize-none rounded-none border-0 bg-transparent py-2 shadow-none ring-0 focus-visible:ring-0 aria-invalid:ring-0 dark:bg-transparent",
className
)}
{...props}
/>
)
}
export {
InputGroup,
InputGroupAddon,
InputGroupButton,
InputGroupText,
InputGroupInput,
InputGroupTextarea,
}
Update the import paths to match your project setup.
Usage#
import {
InputGroup,
InputGroupAddon,
InputGroupButton,
InputGroupTextarea,
} from "@/components/ui/input-group"<form ref={formRef} onSubmit={onSubmit}>
<InputGroup>
<InputGroupTextarea
value={text}
onChange={(event) => setText(event.target.value)}
placeholder="Ask the agent to change your code..."
className="p-3"
/>
<InputGroupAddon align="block-end">
<InputGroupButton
size="icon-sm"
variant="outline"
className="rounded-full"
aria-label="Attach files"
onClick={() => inputRef.current?.click()}
>
<PlusIcon />
</InputGroupButton>
<InputGroupButton
type="submit"
size="icon-sm"
variant="default"
className="ml-auto rounded-full"
disabled={!canSend}
aria-label="Send"
>
<ArrowUpIcon />
</InputGroupButton>
</InputGroupAddon>
</InputGroup>
</form>Attachments#
The attach button opens a hidden file input. Show each file as an Attachment in an addon with align="block-start", with a button to remove it.
Model and Effort#
Put the two Model Selector menus in the block-end addon, between the attach and send buttons. Move ml-auto from the send button to the first menu trigger, so both menus sit next to the send button.
Keyboard#
Enter sends the message. Shift+Enter adds a new line.
onKeyDown={(event) => {
if (event.key === "Enter" && !event.shiftKey) {
event.preventDefault()
formRef.current?.requestSubmit()
}
}}AI SDK#
Send the text and the FileList from the file input.
sendMessage({ text, files })The route streams the reply with result.toUIMessageStreamResponse().
Migrating from AI SDK Elements#
If you added Prompt Input from AI SDK Elements, your project has a components/ai-elements/prompt-input.tsx wrapper. Paste this prompt into your coding agent to rebuild it on Input Group and Attachment. Every export keeps its name and props, so the code that uses it keeps working.
Migrate components/ai-elements/prompt-input.tsx from AI SDK Elements to the shadcn/ui Input Group and Attachment components.
Keep every export, with the same name and props, so the code that imports it keeps working. Only change how each part renders.
1. Install the components: npx shadcn@latest add input-group attachment
2. Read https://ui.shadcn.com/docs/ai-elements/base/prompt-input.md and build Prompt Input the same way.
3. Rebuild each part:
- PromptInput already renders an Input Group. Keep the form, the provider, the attachment state and the command parts as they are.
- PromptInputTextarea renders an InputGroupTextarea with className="p-3".
- PromptInputActionMenuTrigger renders an InputGroupButton with size="icon-sm", variant="outline" and rounded-full, with a PlusIcon.
- PromptInputSubmit renders an InputGroupButton with size="icon-sm", variant="default" and rounded-full, with an ArrowUpIcon while idle. Keep the spinner and stop icons for the other statuses.
- PromptInputHeader shows each attachment as an Attachment with size="sm" and a button to remove it.
- Keep PromptInputSelect, PromptInputHoverCard and the tab parts as they are.
4. Remove the imports the file no longer uses.
5. Run the type checker and fix any errors.