Skip to content
2k
On This Page

Prompt Input

A message field with attachments and a send button.

// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.
import { For, createSignal } from "solid-js"

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 default function PromptInputDemo() {
  const [text, setText] = createSignal("")
  const [files, setFiles] = createSignal<AttachmentFile[]>([])
  const [model, setModel] = createSignal(models[0]!.id)
  const [effort, setEffort] = createSignal(efforts[1]!.id)
  let formRef: HTMLFormElement | undefined
  let inputRef: HTMLInputElement | undefined
  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: SubmitEvent & { currentTarget: HTMLFormElement }) {
    event.preventDefault()
    if (!canSend()) {
      return
    }

    setText("")
    setFiles([])
  }

  function onAttach(event: Event & { currentTarget: HTMLInputElement }) {
    const selected = event.currentTarget.files
    if (!selected) {
      return
    }

    setFiles((current) => [
      ...current,
      ...Array.from(selected, (file) => ({
        id: crypto.randomUUID(),
        name: file.name
      }))
    ])
    event.currentTarget.value = ""
  }

  return (
    <div class="mx-auto w-full max-w-lg py-6">
      <form
        ref={(element) => {
          formRef = element
        }}
        onSubmit={onSubmit}
      >
        <input
          ref={(element) => {
            inputRef = element
          }}
          type="file"
          multiple
          class="sr-only"
          tabindex={-1}
          onChange={onAttach}
        />
        <InputGroup>
          {files().length > 0 && (
            <InputGroupAddon align="block-start" class="flex-wrap">
              {
                <For each={files()}>
                  {(file) => (
                    <Attachment size="sm">
                      <AttachmentMedia>
                        <svg
                          width="24"
                          height="24"
                          viewBox="0 0 24 24"
                          fill="none"
                          stroke="currentColor"
                          stroke-width="2"
                          stroke-linecap="round"
                          stroke-linejoin="round"
                          aria-hidden="true"
                        >
                          <path d="M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z" />
                          <path d="M14 2v5a1 1 0 0 0 1 1h5" />
                          <path d="M10 9H8" />
                          <path d="M16 13H8" />
                          <path d="M16 17H8" />
                        </svg>
                      </AttachmentMedia>
                      <AttachmentContent>
                        <AttachmentTitle>{file.name}</AttachmentTitle>
                      </AttachmentContent>
                      <AttachmentActions>
                        <AttachmentAction
                          aria-label={`Remove ${file.name}`}
                          onClick={() =>
                            setFiles((current) =>
                              current.filter((item) => item.id !== file.id)
                            )
                          }
                        >
                          <svg
                            width="24"
                            height="24"
                            viewBox="0 0 24 24"
                            fill="none"
                            stroke="currentColor"
                            stroke-width="2"
                            stroke-linecap="round"
                            stroke-linejoin="round"
                            aria-hidden="true"
                          >
                            <path d="M18 6 6 18" />
                            <path d="m6 6 12 12" />
                          </svg>
                        </AttachmentAction>
                      </AttachmentActions>
                    </Attachment>
                  )}
                </For>
              }
            </InputGroupAddon>
          )}
          <InputGroupTextarea
            value={text()}
            onInput={(event) => setText(event.currentTarget.value)}
            placeholder="Ask the agent to change your code..."
            onKeyDown={(event) => {
              if (event.key === "Enter" && !event.shiftKey) {
                event.preventDefault()
                formRef?.requestSubmit()
              }
            }}
            class="p-3"
          />
          <InputGroupAddon align="block-end">
            <InputGroupButton
              size="icon-sm"
              variant="outline"
              class="rounded-full"
              aria-label="Attach files"
              onClick={() => inputRef?.click()}
            >
              <svg
                width="24"
                height="24"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="2"
                stroke-linecap="round"
                stroke-linejoin="round"
                aria-hidden="true"
              >
                <path d="M5 12h14" />
                <path d="M12 5v14" />
              </svg>
            </InputGroupButton>
            <DropdownMenu>
              <DropdownMenuTrigger
                render={(triggerProps) => (
                  <InputGroupButton
                    {...triggerProps}
                    size="sm"
                    variant="outline"
                    aria-label={`Model: ${currentModel().name}`}
                    class="ml-auto"
                  >
                    {currentModel().name}
                    <svg
                      width="24"
                      height="24"
                      viewBox="0 0 24 24"
                      fill="none"
                      stroke="currentColor"
                      stroke-width="2"
                      stroke-linecap="round"
                      stroke-linejoin="round"
                      aria-hidden="true"
                    >
                      <path d="m6 9 6 6 6-6" />
                    </svg>
                  </InputGroupButton>
                )}
              />
              <DropdownMenuContent align="start" class="w-48">
                <DropdownMenuRadioGroup
                  value={model()}
                  onValueChange={setModel}
                >
                  {
                    <For each={providers}>
                      {(provider, index) => (
                        <>
                          {index() > 0 && <DropdownMenuSeparator />}
                          <DropdownMenuGroup>
                            <DropdownMenuLabel>
                              {provider.name}
                            </DropdownMenuLabel>
                            {
                              <For each={provider.models}>
                                {(item) => (
                                  <DropdownMenuRadioItem value={item.id}>
                                    {item.name}
                                  </DropdownMenuRadioItem>
                                )}
                              </For>
                            }
                          </DropdownMenuGroup>
                        </>
                      )}
                    </For>
                  }
                </DropdownMenuRadioGroup>
              </DropdownMenuContent>
            </DropdownMenu>
            <DropdownMenu>
              <DropdownMenuTrigger
                render={(triggerProps) => (
                  <InputGroupButton
                    {...triggerProps}
                    size="sm"
                    variant="outline"
                    aria-label={`Effort: ${currentEffort().name}`}
                  >
                    <span class="text-muted-foreground">Effort</span>
                    {currentEffort().name}
                    <svg
                      width="24"
                      height="24"
                      viewBox="0 0 24 24"
                      fill="none"
                      stroke="currentColor"
                      stroke-width="2"
                      stroke-linecap="round"
                      stroke-linejoin="round"
                      aria-hidden="true"
                    >
                      <path d="m6 9 6 6 6-6" />
                    </svg>
                  </InputGroupButton>
                )}
              />
              <DropdownMenuContent align="start" class="w-36">
                <DropdownMenuGroup>
                  <DropdownMenuLabel>Effort</DropdownMenuLabel>
                  <DropdownMenuRadioGroup
                    value={effort()}
                    onValueChange={setEffort}
                  >
                    {
                      <For each={efforts}>
                        {(item) => (
                          <DropdownMenuRadioItem value={item.id}>
                            {item.name}
                          </DropdownMenuRadioItem>
                        )}
                      </For>
                    }
                  </DropdownMenuRadioGroup>
                </DropdownMenuGroup>
              </DropdownMenuContent>
            </DropdownMenu>
            <InputGroupButton
              type="submit"
              size="icon-sm"
              variant="default"
              class="rounded-full"
              disabled={!canSend()}
              aria-label="Send"
            >
              <svg
                width="24"
                height="24"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="2"
                stroke-linecap="round"
                stroke-linejoin="round"
                aria-hidden="true"
              >
                <path d="m5 12 7-7 7 7" />
                <path d="M12 19V5" />
              </svg>
            </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 solidui-cli@latest add input-group attachment dropdown-menu

Install the required Solid UI dependencies:

pnpm dlx solidui-cli@latest add input-group attachment dropdown-menu

Copy and paste the following code into your project.

components/ui/input-group.tsx
import { type ComponentProps, type JSX } from "@solidjs/web"
import { cva, type VariantProps } from "class-variance-authority"
import { omit } from "solid-js"

import { cn } from "~/lib/utils"
import { Button, type ButtonProps } from "~/components/ui/button"
import { Input } from "~/components/ui/input"
import { Textarea } from "~/components/ui/textarea"

type InputGroupProps = ComponentProps<"div">

const InputGroup = (props: InputGroupProps) => (
  <div
    data-slot="input-group"
    role="group"
    {...props}
    class={cn(
      "h-8 rounded-lg border border-input transition-colors in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-disabled:bg-input/50 has-disabled:opacity-50 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-ui=input-group-control]:focus-visible]:border-ring has-[[data-ui=input-group-control]:focus-visible]:ring-3 has-[[data-ui=input-group-control]:focus-visible]:ring-ring/50 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 dark:bg-input/30 dark:has-disabled:bg-input/80 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 group/input-group relative flex w-full min-w-0 items-center outline-none has-[>textarea]:h-auto",
      props.class
    )}
  />
)

const inputGroupAddonVariants = cva(
  "h-auto gap-2 py-1.5 text-sm font-medium text-muted-foreground group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4 flex cursor-text items-center justify-center select-none",
  {
    variants: {
      align: {
        "inline-start": "pl-2 has-[>button]:ml-[-0.3rem] has-[>kbd]:ml-[-0.15rem] order-first",
        "inline-end": "pr-2 has-[>button]:mr-[-0.3rem] has-[>kbd]:mr-[-0.15rem] order-last",
        "block-start":
          "px-2.5 pt-2 group-has-[>input]/input-group:pt-2 [.border-b]:pb-2 order-first w-full justify-start",
        "block-end":
          "px-2.5 pb-2 group-has-[>input]/input-group:pb-2 [.border-t]:pt-2 order-last w-full justify-start"
      }
    },
    defaultVariants: {
      align: "inline-start"
    }
  }
)

type InputGroupAddonProps = ComponentProps<"div"> &
  VariantProps<typeof inputGroupAddonVariants>

const handleInputGroupAddonClick: JSX.EventHandler<
  HTMLDivElement,
  MouseEvent
> = (event) => {
  if ((event.target as HTMLElement).closest("button")) {
    return
  }
  event.currentTarget.parentElement?.querySelector("input")?.focus()
}

const InputGroupAddon = (props: InputGroupAddonProps) => {
  const others = omit(props, "class", "align")
  const align = () => props.align ?? "inline-start"
  return (
    <div
      role="group"
      data-slot="input-group-addon"
      data-align={align()}
      class={cn(inputGroupAddonVariants({ align: align() }), props.class)}
      onClick={handleInputGroupAddonClick}
      {...others}
    />
  )
}

const inputGroupButtonVariants = cva(
  "gap-2 text-sm flex items-center shadow-none",
  {
    variants: {
      size: {
        xs: "h-6 gap-1 rounded-[calc(var(--radius)-3px)] px-1.5 [&>svg:not([class*='size-'])]:size-3.5",
        sm: "",
        "icon-xs": "size-6 rounded-[calc(var(--radius)-3px)] p-0 has-[>svg]:p-0",
        "icon-sm": "size-8 p-0 has-[>svg]:p-0"
      }
    },
    defaultVariants: {
      size: "xs"
    }
  }
)

type InputGroupButtonProps = Omit<ButtonProps, "size"> &
  VariantProps<typeof inputGroupButtonVariants> & {
    type?: "button" | "submit" | "reset"
  }

const InputGroupButton = (props: InputGroupButtonProps) => {
  const others = omit(props, "class", "type", "variant", "size")
  const size = () => props.size ?? "xs"
  const variant = () => props.variant ?? "ghost"
  const type = () => props.type ?? "button"
  return (
    <Button
      type={type()}
      data-size={size()}
      variant={variant()}
      class={cn(inputGroupButtonVariants({ size: size() }), props.class)}
      {...others}
    />
  )
}

type InputGroupTextProps = ComponentProps<"span">

const InputGroupText = (props: InputGroupTextProps) => (
  <span
    {...props}
    class={cn(
      "gap-2 text-sm text-muted-foreground [&_svg:not([class*='size-'])]:size-4 flex items-center [&_svg]:pointer-events-none",
      props.class
    )}
  />
)

type InputGroupInputProps = ComponentProps<"input">

const InputGroupInput = (props: InputGroupInputProps) => (
  <Input
    data-slot="input-group-control"
    data-ui="input-group-control"
    {...props}
    class={cn("rounded-none border-0 bg-transparent shadow-none ring-0 focus-visible:ring-0 disabled:bg-transparent aria-invalid:ring-0 dark:bg-transparent dark:disabled:bg-transparent flex-1", props.class)}
  />
)

type InputGroupTextareaProps = ComponentProps<"textarea">

const InputGroupTextarea = (props: InputGroupTextareaProps) => (
  <Textarea
    data-slot="input-group-control"
    data-ui="input-group-control"
    {...props}
    class={cn("rounded-none border-0 bg-transparent py-2 shadow-none ring-0 focus-visible:ring-0 disabled:bg-transparent aria-invalid:ring-0 dark:bg-transparent dark:disabled:bg-transparent flex-1 resize-none", props.class)}
  />
)

export {
  InputGroup,
  InputGroupAddon,
  InputGroupButton,
  InputGroupInput,
  InputGroupText,
  InputGroupTextarea,
  type InputGroupAddonProps,
  type InputGroupButtonProps,
  type InputGroupInputProps,
  type InputGroupProps,
  type InputGroupTextareaProps,
  type InputGroupTextProps
}

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..."
      class="p-3"
    />
    <InputGroupAddon align="block-end">
      <InputGroupButton
        size="icon-sm"
        variant="outline"
        class="rounded-full"
        aria-label="Attach files"
        onClick={() => inputRef.current?.click()}
      >
        <PlusIcon />
      </InputGroupButton>
      <InputGroupButton
        type="submit"
        size="icon-sm"
        variant="default"
        class="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.

Prompt
Migrate components/ai-elements/prompt-input.tsx from AI SDK Elements to the Solid 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 solidui-cli@latest add input-group attachment
2. Read https://www.solid-ui.com/docs/ai-elements/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 class="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.