HextaUI

File input (UI SDK): Prompt attachments

With variant="composer", the drop zone is the card around a message box, and layout="chips" lists files as compact chips. pasteTarget takes pasted screenshots from the text area, while pasted text stays text.

"use client"

import * as React from "react"
import { IconArrowUp, IconPaperclip } from "@tabler/icons-react"

import { Button } from "@/components/ui/button"
import {
  FileInput,
  FileInputDropzone,
  FileInputItem,
  FileInputList,
  FileInputRejections,
  FileInputTrigger,
} from "@/components/ui/ui-sdk-file-input"

function UiSdkFileInputAttachments() {
  const message = React.useRef<HTMLTextAreaElement>(null)

  return (
    <FileInput multiple maxFiles={4} maxSize={20_000_000} className="max-w-lg">
      <FileInputDropzone
        variant="composer"
        pasteTarget={() => message.current}
      >
        <FileInputList aria-label="Attachments" layout="chips">
          <FileInputItem />
        </FileInputList>
        <textarea
          ref={message}
          aria-label="Message"
          placeholder="Ask anything, or paste a screenshot"
          rows={2}
          className="field-sizing-content max-h-40 min-h-12 w-full resize-none bg-transparent px-2 py-1.5 text-sm outline-none placeholder:text-muted-foreground pointer-coarse:text-touch"
        />
        <div className="flex items-center justify-between">
          <FileInputTrigger
            variant="ghost"
            size="icon-sm"
            aria-label="Attach files"
          >
            <IconPaperclip aria-hidden="true" />
          </FileInputTrigger>
          <Button type="button" size="icon-sm" shape="pill" aria-label="Send">
            <IconArrowUp aria-hidden="true" />
          </Button>
        </div>
      </FileInputDropzone>
      <FileInputRejections />
    </FileInput>
  )
}

export { UiSdkFileInputAttachments }

This adds the example as components/examples/ui-sdk-file-input/attachments.tsx, together with the File input component and the HextaUI theme tokens it needs.

pnpm dlx shadcn@latest add https://hextaui.com/r/ui-sdk-file-input-attachments.json

To add only the component, follow the File input installation.

Props in this example

The File input props this example sets, from the API reference.

PropTypeDefault
multiple
booleanfalse
maxFiles
number–
maxSizeIn bytes.
number–
PropTypeDefault
variantA dashed zone, a card that wraps a message composer, or a full-page overlay shown while dragging.
"default" | "composer" | "overlay""default"
pasteTargetSomewhere else to take pasted files from.
"document" | string | Element | () => Element–
PropTypeDefault
variant
Button variant"outline"
size
Button size"sm"
PropTypeDefault
layoutRows, square image tiles, or compact chips. Items take their look from it.
"list" | "grid" | "chips""list"

Every prop is in the File input API reference.

See them all, with keyboard support and accessibility notes, on the File input page.