HextaUI

File input (UI SDK): Accepted types and limits

accept takes MIME types, wildcards and extensions. maxFiles, minSize and maxSize set the limits, and validate adds checks of your own. FileInputRejections lists each file that was left out with every reason, until the next accepted file.

Drop up to 3 PDFs

2 MB each, no empty files and no duplicates.

"use client"

import * as React from "react"

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

function UiSdkFileInputLimits() {
  const [files] = React.useState(createFileInputController)

  return (
    <FileInput
      multiple
      controller={files}
      accept=".pdf"
      maxFiles={3}
      minSize={1}
      maxSize={2_000_000}
      validate={(file) =>
        files.getValue().some((other) => other.name === file.name)
          ? "Already added"
          : null
      }
      className="max-w-md"
    >
      <FileInputDropzone className="min-h-32">
        <FileInputDropzoneTitle>Drop up to 3 PDFs</FileInputDropzoneTitle>
        <FileInputDropzoneDescription>
          2 MB each, no empty files and no duplicates.
        </FileInputDropzoneDescription>
        <FileInputTrigger className="mt-3">Choose PDFs</FileInputTrigger>
      </FileInputDropzone>
      <FileInputRejections />
      <FileInputList aria-label="PDFs">
        <FileInputItem />
      </FileInputList>
    </FileInput>
  )
}

export { UiSdkFileInputLimits }

This adds the example as components/examples/ui-sdk-file-input/limits.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-limits.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
accept
string | string[]–
multiple
booleanfalse
maxFiles
number–
maxSizeIn bytes.
number–
minSizeIn bytes.
number–
validateReturn a reason to reject the file, after the built-in checks.
(file: File) => string | null–
controllerFrom createFileInputController().
FileInputController–

Every prop is in the File input API reference.

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