Upload
Native <input type="file"> driven uploader with an optional drag zone. The upload request is
provided by the caller via the request prop (zero runtime dependencies; no built-in HTTP client).
Basic usage
The request is provided by the caller (no built-in HTTP client); the demo simulates progress with a timer.
Basic usage (local select & validation)
Drag & drop with custom request (simulated upload progress)
Disabled & max count
import { LhUpload } from '@lh-ui/react'
export default function Demo() {
return <LhUpload maxSize={1024 * 1024} accept={['.png', '.jpg']} />
}
accept also accepts a comma-separated string (e.g. accept=".png,.jpg").
Drag & drop + custom request
request receives { file, onProgress } and returns Promise<{ url?: string }>: progress is
driven by the onProgress callback (call it from your XHR's onprogress handler in real
integrations); resolve with the server URL on success or throw on failure.
import { LhUpload } from '@lh-ui/react'
import type { LhUploadRequest } from '@lh-ui/react'
const fakeRequest: LhUploadRequest = ({ file, onProgress }) =>
new Promise((resolve) => {
let percent = 0
const timer = setInterval(() => {
percent += 20
onProgress(percent)
if (percent >= 100) {
clearInterval(timer)
resolve({ url: `https://example.com/${file.name}` })
}
}, 200)
})
export default function Demo() {
return <LhUpload drag multiple request={fakeRequest} />
}
Disabled & max count
disabled turns off uploading; maxCount caps the number of uploaded files.
import { LhUpload } from '@lh-ui/react'
export default function Demo() {
return (
<>
<LhUpload disabled />
<LhUpload maxCount={2} />
</>
)
}
LhUpload Props
| Prop | Description | Type | Options | Default |
|---|---|---|---|---|
| children | Custom trigger content (plus's default slot) | ReactNode | — | — |
| multiple | Allow multiple files | boolean | — | false |
| drag | Drag & drop zone | boolean | — | false |
| disabled | Disabled | boolean | — | false |
| accept | Allowed extensions / MIME: array (['.png', 'image/*']) or comma string ('.png,.jpg') | string | string[] | — | — |
| maxSize | Max size per file in bytes | number | — | 5 * 1024 * 1024 (LH_UPLOAD_MAX_SIZE) |
| maxCount | Max file count (0 = unlimited) | number | — | 0 |
| request | Upload request function (without it only local selection & validation) | (options: { file: File; onProgress: (percent: number) => void }) => Promise<{ url?: string }> | — | — |
| onChange | Fired when the file list changes (after adding, after upload ends, after removal) | (files: LhUploadFile[]) => void | — | — |
| onSuccess | Fired when a single file uploads successfully | (file: LhUploadFile) => void | — | — |
| onError | Fired when a single file upload fails | (file: LhUploadFile, reason: string) => void | — | — |
| onRemove | Fired after a file is removed | (uid: string) => void | — | — |
| sx | Layout shorthand | SxProps | — | — |
multiple / drag / disabled / accept / maxSize / maxCount / request match lh-ui-plus's
LhUpload props; plus's @change / @success / @error / @remove emits map to
onChange / onSuccess / onError / onRemove, and the default slot becomes children.
The native <input type="file"> is visually hidden but kept in the accessibility tree (named via
aria-label); the trigger carries role="button" + tabindex with Enter / Space opening the file
picker, and is taken out of interaction when disabled (aria-disabled); uploading file items embed
a role="progressbar" with aria-valuenow / aria-valuemin / aria-valuemax; validation failures
are announced via role="alert"; each remove button is named "Remove + file name".
Styles
import '@lh-ui/react/style/upload'