Hulian UIv0.93.5413 components0 components
  • Start
  • Components
  • Blocks
  • Pages
  • Demos
  • Changelog
ChineseEnglish
  • ComponentsComponents
  • ThemeTheme

Buttons

  • Button
  • ShimmerButton
  • InteractiveHoverButton
  • RainbowButton
  • PulsatingButton
  • RippleButton
  • ButtonGroup
  • SocialButton

Basic Inputs

  • Input
  • Textarea
  • CellEditor
  • Select
  • Checkbox
  • CheckboxGroup
  • Radio
  • Switch
  • Toggle
  • Segmented
  • Slider
  • NumberField
  • ElasticSlider

Advanced Inputs

  • MathTextarea
  • QuestionEditor
  • QuestionAnswer
  • MathField
  • SecretField
  • PasswordGenerator
  • Combobox
  • RemoteSelect
  • Listbox
  • Mentions
  • InputOTP
  • Rating
  • Upload
  • RegionSelect
  • ImageCropper
  • ScopeMatrix
  • Transfer
  • Cascader
  • TreeSelect
  • RegionCascader
  • CountrySelect
  • MarkdownEditor
  • Novel editor
  • RichTextEditor
  • CodeEditor
  • IssueReporter
  • ColorPicker
  • ColorField
  • ColorSwatchPicker
  • Choicebox
  • EmojiPicker
  • VoiceRecord
  • IconPicker
  • InspectorPanel

Date and Time

  • Calendar
  • DatePicker
  • DateTimePicker
  • DateRangePicker
  • TimePicker
  • TimeField

Form Frameworks

  • Form
  • ModalForm / DrawerForm
  • ProForm
  • StepsForm
  • LoginForm
  • AuthPanel
  • ClickCaptcha
  • Label
  • Field
  • SearchForm

Upload

upload

Selects files through click or drag-and-drop with validation and progress states.

Usage

Basic usage (drag and drop area)

Default dropzone form: click or drag the file, the file that passes the verification is thrown out by onSelect, and the status/progress is backfilled by the consumer to files.

Click or drag files here
Supports any format, single file ≤ 5MB
tsx
<Upload
  multiple
  hint="Support any format, single file ≤ 5MB"
  maxSize={5 * 1024 * 1024}
  files={files}
  onSelect={(picked) => /* Upload and backfill files */}
  onRemove={(id) => /* Remove */}
/>

Button form

variant="button" Harvest single button, accept limited file type.

tsx
<Upload variant="button" accept="image/*" buttonLabel="Upload avatar" />

File List and Status

files Controlled display: success / uploading (with progress bar + percentage) / error (with error copy) three-state coexistence.

  • report-2026.pdf1.8 MB
  • cover.png62%
  • huge-video.movExceeds the upper limit of 5MB
tsx
const files = [
  { id: "a", name: "report-2026.pdf", size: 1.8 * 1024 * 1024, status: "success" },
  { id: "b", name: "cover.png", size: 820 * 1024, status: "uploading", progress: 62 },
  { id: "c", name: "huge-video.mov", status: "error", error: "Exceeds 5MB upper limit" },
];

<Upload variant="button" files={files} onRemove={(id) => remove(id)} />

Automatic upload (useUpload)

The transport layer is split into independent hook: request is provided by you (fetch/XHR/OSS SDK is optional), hook only handles queuing, concurrency gate, progress backfill and cancellation. The action/headers/envelope shape is not recognized in the library.

Click or drag files here
Automatically upload files after selecting them, up to 5 files
0/5 selected
tsx
const up = useUpload({
  request: async (file, { onProgress, signal }) => {
    const fd = new FormData();
    fd.append("file", file);
    const res = await fetch("/api/upload", { method: "POST", body: fd, signal });
    onProgress(100);
    return { url: (await res.json()).data.url }; // Envelope unpacking is at the application layer
  },
  concurrency: 2,
});

<Upload multiple limit={5} files={up.files} onSelect={up.add} onRemove={up.remove} />

Maximum quantity limit

After reaching limit, the trigger is automatically disabled and "n/limit selected" is displayed; files exceeding the remaining quota in this selection are entered into onReject (reason="limit").

Click or drag files here
  • report-2026.pdf1.8 MB
  • cover.png62%
  • huge-video.movExceeds the upper limit of 5MB
3/3 selected
tsx
<Upload
  multiple
  limit={3}
  files={files}
  onSelect={add}
  onRemove={remove}
  onReject={(rs) => rs.some((r) => r.reason === "limit") && toast("Max 3 ")}
/>

Thumbnail + drag and drop to order

renderPreview is the rendering hook (local files use URL.createObjectURL (raw), historical files use url); sortable + onSort open the handle and drag to adjust the sequence, the sequence is still written back by you files.

  • banner-1.pngbanner-1.png240.0 KB
  • banner-2.pngbanner-2.png310.0 KB
  • banner-3.pngbanner-3.png180.0 KB
3/3 selected
tsx
<Upload
  multiple
  accept="image/*"
  limit={6}
  sortable
  files={files}
  onSelect={add}
  onRemove={remove}
  onSort={setFiles}
  renderPreview={(f) => <img src={f.url ?? preview(f.raw)} alt={f.name} />}
/>

Disabled

Click or drag files here
Disabled
tsx
<Upload disabled hint="Disabled" />

When to use

Use Upload to select or drop files and display a controlled list with thumbnails, status, progress, and optional sorting.

Layering is the component's central contract:

  • <Upload> is presentation and status only. It performs no network request. After accept, maxSize, and limit validation, it emits onSelect(File[]); consumers write status back through controlled files.
  • useUpload({ request, concurrency }) is the transport layer. It owns queuing, concurrency, progress, cancellation, and retry, while the supplied request defines how bytes are sent.

request has the signature (file, { onProgress, signal }) => Promise<{ url }>. The library deliberately omits action, headers, withCredentials, and transformResponse: authentication and response-envelope handling belong in the application's request closure.

Use variant="dropzone" for a drop area and variant="button" for a compact trigger. Use ImageCropper to crop selected images, or Sortable when the workflow only reorders existing items.

Import

ts
import { Upload, useUpload, matchesAccept, moveUploadFile } from "@hulianui/ui"

Props

NameTypeDefaultDescription
acceptstring-Native accept filter, such as "image/*,.pdf"; also validates dropped files.
multiplebooleanfalseWhether to allow selecting more than one file.
disabledbooleanfalseWhether to disable file selection and dropping.
maxSizenumber-Maximum size of each file in bytes; oversized files are reported through onReject with reason "size".
limitnumber-Maximum file count, based on files.length. At the limit, the trigger is disabled and shows “selected n/limit”; excess files are reported with reason "limit".
variant"dropzone" | "button" | "picture-card""dropzone"Presentation: drag-and-drop area, compact button, or square thumbnail wall with a trailing dashed trigger card that hides automatically at limit.
size"sm" | "md" | "lg""md"Size step for dropzone height, button height, or picture-card square size (80 / 96 / 112px).
namestring-The name of the inner <input type="file">. Only with a name is it a real form control: a native <form> plus new FormData(form) can read the file, and required is validated by the browser.
requiredboolean-Native required validation, forwarded to the inner input. Provide name as well, otherwise the form never sees the control. It also attaches a screen-reader-only "required" note to the trigger.
aria-requiredboolean | "true" | "false"-The semantic required marker, normally injected by <Field required>. You rarely pass it yourself. It only turns on the accessibility half (the screen-reader-only note on the trigger); it does not enable native required validation.
inputRefRef<HTMLInputElement>-Access to the inner input for custom validation, manual clearing, or registration with a third-party form library.
resetInputAfterSelectbooleantrue without name, false with nameWhether to clear input.value after a selection. Clearing allows picking the same file twice; keeping the value is what lets FormData read it.
filesUploadFile[]-Controlled display list, including status, progress, and URL metadata. Omit it to hide the list.
renderPreview(file: UploadFile) => ReactNode-Thumbnail renderer. Uses a 40 px preview slot in list mode, or replaces the default <img> in picture-card mode.
renderBadge(file: UploadFile, index: number) => ReactNode-Dynamic top-left corner badge renderer for picture-card tiles (e.g. "Cover" for index 0; takes precedence over file.badge).
sortablebooleanfalseEnables drag reordering in list and picture-card modes when onSort is also provided.
classNamestring-Additional class name for the container.

Events

EventTypeDescription
onSelect(files: File[]) => voidCalled with files that pass validation.
onReject(rejections: UploadRejection[]) => voidCalled for rejected files with reason "type", "size", or "limit".
onRemove(id: string) => voidCalled with the file ID when its remove button is clicked.
onPreview(file: UploadFile, index: number) => voidPreview callback for picture-card tiles; when omitted, clicking preview opens the built-in ImageViewer.
onRetry(id: string) => voidCalled with the file ID when the retry button on a failed row is clicked. The button renders only when this handler is provided, matching onRemove; connect it to retry from useUpload.
onSort(files: UploadFile[]) => voidCalled with the reordered list after a drag; write it back to controlled files.

Slots

SlotTypeDescription
labelReactNodeDropzone label; the default is "\u70b9\u51fb\u6216\u62d6\u62fd\u6587\u4ef6\u5230\u6b64\u5904", built-in Chinese copy meaning “Click or drag files here.”
hintReactNodeSupporting dropzone text, such as accepted formats or size limits.
buttonLabelReactNodeButton-mode label; the default is "\u9009\u62e9\u6587\u4ef6", built-in Chinese copy meaning “Choose files.”
childrenReactNodeCustom dropzone content that replaces label and hint.
UploadFile: { id; name; size?; status?: "ready"\|"uploading"\|"success"\|"error"; progress?; error?; url?; raw? } · progress displays a progress bar and percentage only for status="uploading"; values are clamped internally to 0-100. · url and raw are metadata only. Upload does not interpret them; they are available to renderPreview and consumer code. onSelect still emits File[].

useUpload (transport layer)

ts
const up = useUpload({ request, concurrency?, onChange?, onSuccess?, onError? })
// up: { files, add, remove, retry, reorder, clear, uploading }
OptionsTypeDefaultDescription
request(file, { onProgress, signal }) => Promise<{ url }>-Required transport implementation. Forward signal to fetch or XHR.
concurrencynumber3Maximum concurrent uploads; excess files queue, and values below 1 fall back to 1.
onChange(files: UploadFile[]) => void-Called after any change to the file list.
onSuccess / onError(file, result | error) => void-Called when an individual upload settles; cancellation through abort does not trigger onError.
ReturnsDescription
filesControlled file list to pass directly to <Upload files>.
addHandler for <Upload onSelect> that queues files and starts uploads within the concurrency limit.
removeHandler for <Upload onRemove> that also aborts an in-progress task.
retryHandler for <Upload onRetry> that retries one failed item.
reorderConnect to <Upload onSort>; it changes list order without affecting upload tasks.
clearCancels every task and clears the list.
uploadingWhether any task is queued or in progress.

Example

Automatic upload with progress, concurrency, and a file-count limit:

tsx
const up = useUpload({
  request: async (file, { onProgress, signal }) => {
    const fd = new FormData();
    fd.append("file", file);
    const res = await fetch("/api/upload", { method: "POST", body: fd, signal });
    onProgress(100);
    return { url: (await res.json()).data.url }; // Unwrap the API envelope in the application layer
  },
  concurrency: 3,
});

<Upload multiple limit={5} files={up.files} onSelect={up.add} onRemove={up.remove} onRetry={up.retry} />

Native <form> plus FormData, with no React state and required left to the browser:

tsx
<form
  onSubmit={(e) => {
    e.preventDefault();
    const fd = new FormData(e.currentTarget); // fd.get("file") is the File
    void fetch("/api/upload", { method: "POST", body: fd });
  }}
>
  <Upload name="file" required accept=".pdf" size="sm" hint="PDF only, 10 MB max" />
  <button type="submit">Submit</button>
</form>

If you want a real progress bar, use XHR (fetch has no upload progress event):

ts
const request: UploadRequest = (file, { onProgress, signal }) =>
  new Promise((resolve, reject) => {
    const xhr = new XMLHttpRequest();
    xhr.upload.onprogress = (e) => e.lengthComputable && onProgress((e.loaded / e.total) * 100);
    xhr.onload = () => resolve({ url: JSON.parse(xhr.responseText).url });
    xhr.onerror = () => reject(new Error("Network error"));
    signal.addEventListener("abort", () => xhr.abort());
    xhr.open("POST", "/api/upload");
    xhr.send(new FormData(/* ... */));
  });

Image gallery with thumbnails and drag sorting:

tsx
<Upload
  multiple
  accept="image/*"
  limit={6}
  sortable
  files={up.files}
  onSelect={up.add}
  onRemove={up.remove}
  onSort={up.reorder}
  renderPreview={(f) => <img src={f.url ?? objectUrl(f.raw)} alt={f.name} />}
/>

Fully controlled transport without useUpload:

tsx
<Upload variant="button" accept="image/*" files={files} onSelect={add} onRemove={remove} />

Usage guidelines

  • <Upload> never uploads by itself. Pair it with useUpload for automatic transport, or write status, progress, error, and url back through controlled files when managing requests yourself.
  • Without name there is no native form path. An input without a name never appears in the entries of FormData, and required is never validated by the browser. Neither omission raises an error; both simply do nothing.
  • Providing name also changes three defaults, all of which apply only when a name is present. First, the value is no longer cleared after a selection, because clearing it means FormData always reads an empty control; the cost is that picking the same file twice in a row no longer fires onSelect. Set resetInputAfterSelect explicitly if you need that behavior instead, but then FormData cannot read the file: the two cannot both apply. Second, dropped files are written back into input.files, which native drag and drop does not do, and files rejected by accept, maxSize, or limit are removed from it so the form cannot submit what the interface just refused. Third, reaching limit no longer disables the input, because a disabled control is skipped entirely by FormData and the already selected file would vanish on submit; the trigger itself stays disabled, so the picker cannot be opened.
  • Writing back to input.files depends on the DataTransfer constructor. Test environments such as jsdom do not provide it, so the write-back is skipped silently while onSelect still works. Do not assert on FormData contents after a drop in jsdom.
  • The retry button on a failed row appears only when onRetry is provided. useUpload has had retry all along, but the component does not decide on your behalf whether a given failure deserves a retry entry; wire it up with onRetry={up.retry}.
  • The library does not unwrap backend envelopes. Your request closure must extract { url } from shapes such as code/data/msg before returning.
  • sortable requires onSort because ordering is controlled. Supplying sortable alone intentionally falls back to a static list.
  • renderPreview runs on every render. Do not call URL.createObjectURL directly inside it or URLs will leak. Cache by file ID and call revokeObjectURL during cleanup; the showcase's useObjectUrls demonstrates the pattern.
  • limit counts controlled files.length. Without files, the existing count is treated as zero, so the limit can reject an oversized single selection but cannot prevent accumulation across selections.
  • useUpload.remove calls abort(), but cancellation reaches the transport only if request forwards signal. Late resolutions are discarded and cannot revive removed rows.
  • Enabling sortable introduces a static dependency on @dnd-kit/*, shared with Sortable and Kanban. Under source distribution it may be bundled even when a specific Upload instance is not sortable.
  • The required state is exposed to assistive tech through a description, not aria-required (#294): the dropzone is a role="button" element and the button variant is a real <button>, and aria-required is only valid on input-like roles, so screen readers ignore it there. Passing required (or placing Upload inside <Field required>) attaches a screen-reader-only "Required" note to the trigger.
  • <Field required> only sets the semantic marker; it does not turn on native required validation. To have the browser block submission, pass required yourself together with name.
  • The trigger's own aria-describedby carries hint plus the required note, so Field's description / error do not travel that path. Put explanatory copy in the component's hint.

Related

Sortable · ImageCropper · SecretField · Combobox · Listbox · Progress

Playground

Click or drag files here
Support any format
<Upload
  variant="dropzone"
  multiple
  maxSize={5 * 1024 * 1024}
  files={files}
  onSelect={(picked) => /* Upload and backfill files */}
  onRemove={(id) => /* Remove */}
/>
PreviousRatingFormsNextRegionSelect

On this page

  • Usage
  • Documentation
    • When to use
    • Import
    • Props
    • Events
    • Slots
    • useUpload (transport layer)
    • Example
    • Usage guidelines
    • Related
  • Playground