Skip to content

TkxFileUpload

Dropzone variant

Upload files

JPG, PNG or PDF. Up to 10 MB each, 5 files max.

Files queued: 0

import { TkxFileUpload } from 'tekivex-ui';
<TkxFileUpload
multiple
accept="image/*,application/pdf"
maxSize={10 * 1024 * 1024}
maxFiles={5}
onChange={(files) => console.log(files)}
hint="JPG, PNG or PDF. Up to 10MB each."
/>
Compact button variant
{/* Default — full drop zone with icon and CTA */}
<TkxFileUpload variant="dropzone" />
{/* Compact — single button, no drop zone */}
<TkxFileUpload variant="button" label="Choose files" />
<TkxFileUpload
accept=".pdf,.docx" // file picker filter
maxSize={5 * 1024 * 1024} // 5MB per file
maxFiles={3} // up to 3 files
onError={(err) => toast.error(err.message)}
/>

Errors fire when:

  • File MIME type doesn’t match accept
  • File size exceeds maxSize
  • Total file count exceeds maxFiles
<TkxFileUpload
accept="image/*"
preview // shows thumbnail per file
onChange={handleFiles}
/>

Previews use URL.createObjectURL + auto-revoke on unmount, so memory leaks are handled.

The default label, drop-zone text, and hint follow the active locale. Set <I18nProvider locale="hi-IN"> and the component picks up Hindi strings.

{/* Spanish auto-localised */}
<I18nProvider locale="es-ES">
<TkxFileUpload />
{/* renders with "Soltar archivos aquí o" + "Explorar" */}
</I18nProvider>
  • The drop zone is a real <button> — keyboard reachable, focus indicators
  • File picker opens on click AND Enter / Space
  • Drag-over state announces via aria-busy on the dropzone
  • Each accepted file gets a labelled remove button
  • Progress bars use role="progressbar" with aria-valuenow
  • Error state uses role="alert" so screen readers announce immediately

TkxFileUpload only handles the client side — collecting and validating files. Wire your own POST/PUT to the server:

<TkxFileUpload
onChange={async (files) => {
for (const f of files) {
const fd = new FormData();
fd.append('file', f.file);
await fetch('/api/upload', { method: 'POST', body: fd });
}
}}
/>
PropTypeRequiredDescription
acceptstringNative <input accept> filter (e.g. 'image/*,.pdf').
multiplebooleanAllow multiple selection. Defaults to false.
maxSizenumberPer-file size cap in bytes.
maxFilesnumberTotal file count cap.
onChange(files: UploadedFile[]) => voidFires on every accept.
onError(err: Error) => voidValidation errors.
labelstringDrop-zone CTA. Localised by default.
hintstringHelper text below CTA.
previewbooleanShow image previews. Defaults to true.
dragDropbooleanEnable drag-and-drop. Defaults to true.
variant'dropzone' | 'button'Defaults to dropzone.

src/components/TkxFileUpload.tsx