Skip to main content

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​

Upload

The request is provided by the caller (no built-in HTTP client); the demo simulates progress with a timer.

Basic usage (local select & validation)

Select file

Drag & drop with custom request (simulated upload progress)

Drop files here or click to upload

Disabled & max count

Select file
Select file
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​

PropDescriptionTypeOptionsDefault
childrenCustom trigger content (plus's default slot)ReactNode——
multipleAllow multiple filesboolean—false
dragDrag & drop zoneboolean—false
disabledDisabledboolean—false
acceptAllowed extensions / MIME: array (['.png', 'image/*']) or comma string ('.png,.jpg')string | string[]——
maxSizeMax size per file in bytesnumber—5 * 1024 * 1024 (LH_UPLOAD_MAX_SIZE)
maxCountMax file count (0 = unlimited)number—0
requestUpload request function (without it only local selection & validation)(options: { file: File; onProgress: (percent: number) => void }) => Promise<{ url?: string }>——
onChangeFired when the file list changes (after adding, after upload ends, after removal)(files: LhUploadFile[]) => void——
onSuccessFired when a single file uploads successfully(file: LhUploadFile) => void——
onErrorFired when a single file upload fails(file: LhUploadFile, reason: string) => void——
onRemoveFired after a file is removed(uid: string) => void——
sxLayout shorthandSxProps——
Vue equivalent

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.

Accessibility

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'