import { Component } from '@angular/core';
import { WrFileUpload } from 'ngwr/file-upload';
@Component({ imports: [WrFileUpload] })
export class MyComponent {}File Upload
Pick files by dropping them on a zone or browsing.
Installation
Import the class, and @use the entry point in your global styles: without it the component renders unstyled.
Single file
The value is the last accepted File, or null.
<wr-file-upload [(value)]="file" />Multiple files
multiple makes the value a File[]; maxFiles caps it.
<wr-file-upload [(value)]="files" [multiple]="true" [maxFiles]="5" />Constrained
accept and maxSize (bytes) filter files; the rest arrive in (rejected).
<wr-file-upload
[(value)]="avatar"
accept=".png,.jpg,image/webp"
[maxSize]="2 * 1024 * 1024"
helperText="PNG, JPG or WebP, up to 2 MB"
(rejected)="onRejected($event)"
/>Types
interface WrFileUploadRejection {
file: File;
reason: WrFileUploadRejectionReason;
}
type WrFileUploadRejectionReason = 'type' | 'size' | 'count';| Name | Description | Type | Default |
|---|---|---|---|
WrFileUploadRejection | One rejected file, emitted via (rejected). | interface | — |
filerequired | The rejected File object. | File | — |
reasonrequired | Why it was rejected. | WrFileUploadRejectionReason | — |
WrFileUploadRejectionReason | Rejection cause. | 'type' | 'size' | 'count' | — |
API
| Name | Description | Type | Default |
|---|---|---|---|
multiple | Allow multiple files. Single mode replaces on each add. | boolean | false |
accept | accept attribute — comma-separated MIME types or extensions. | string | '' |
maxSize | Max bytes per file. 0 disables the check. | number | 0 |
maxFiles | Max files (multi mode only). 0 disables the check. | number | 0 |
showList | Render the picked-files list below the zone. | boolean | true |
disabled | Disable interaction. Bound automatically from the field's disabled state when used with [formField]. | boolean | false |
readonly | Refuse changes to the selection while the zone stays focusable and the files still submit. Bound automatically from the field's readonly state when used with [formField]. The zone stops opening the picker, a drop is refused and the per-file remove buttons go inert — but the list stays readable, which is the point. No aria-readonly: the zone is a role="button", and ARIA does not define the state for that role, so aria-disabled would be the only mirror available and it would say the wrong thing. | boolean | false |
pickLabel | Primary call-to-action label. Falls back to fileUpload.browse. | string | null | null |
dropLabel | Secondary instruction below the CTA. Falls back to fileUpload.dropZone. | string | null | null |
dropZoneLabel | Overrides the drop zone's accessible name. Unset, the zone is named by its visible copy, after the field's label inside a <wr-form-field>. An override must contain that copy, or speech input cannot reach the control (WCAG 2.5.3). | string | null | null |
removeFileLabel | Remove-file button aria-label. Falls back to fileUpload.removeFile. | string | null | null |
helperText | Optional helper text shown below the labels (e.g. accepted formats). | string | '' |
value | Selected file(s). Bound by [formField], or two-way via [(value)]. Shape follows multiple: a single File (or null), or a File[] array. | File | readonly File[] | null | null |
(rejected) | Emitted when files are rejected for type / size / count reasons. | readonly WrFileUploadRejection[] | — |
(touch) | Emitted on commit so a bound field can mark itself touched. | void | — |
CSS variables
Set these on the component's selector or a wrapper, not on :root: the defaults are declared on ngwr/file-upload's own element.
| Variable | Default | Declared on |
|---|---|---|
--wr-file-upload-font-family | var(--wr-font-family-base) | .wr-file-upload |
--wr-file-upload-hint-font-size | var(--wr-text-sm) | .wr-file-upload__hint |
--wr-file-upload-hint-gap | var(--wr-space-xs) | .wr-file-upload__hint |
--wr-file-upload-hint-line-height | var(--wr-text-sm-leading) | .wr-file-upload__hint |
--wr-file-upload-hint-small-font-size | var(--wr-text-xs) | .wr-file-upload__hint |
--wr-file-upload-hint-small-margin-top | var(--wr-space-xs) | .wr-file-upload__hint |
--wr-file-upload-hint-strong-font-weight | var(--wr-font-weight-semibold) | .wr-file-upload__hint |
--wr-file-upload-item-border | var(--wr-border-base) | .wr-file-upload__item |
--wr-file-upload-item-font-size | var(--wr-text-sm) | .wr-file-upload__item |
--wr-file-upload-item-gap | var(--wr-space-md) | .wr-file-upload__item |
--wr-file-upload-item-line-height | var(--wr-text-sm-leading) | .wr-file-upload__item |
--wr-file-upload-item-padding-x | var(--wr-space-md) | .wr-file-upload__item |
--wr-file-upload-item-padding-y | var(--wr-space-sm) | .wr-file-upload__item |
--wr-file-upload-item-radius | var(--wr-border-radius-base) | .wr-file-upload__item |
--wr-file-upload-list-gap | var(--wr-space-sm) | .wr-file-upload__list |
--wr-file-upload-list-margin-top | var(--wr-space-md) | .wr-file-upload__list |
--wr-file-upload-remove-padding | var(--wr-space-xs) | .wr-file-upload__remove |
--wr-file-upload-remove-radius | var(--wr-border-radius-sm) | .wr-file-upload__remove |
--wr-file-upload-zone-border | var(--wr-border-base) | .wr-file-upload__zone |
--wr-file-upload-zone-gap | var(--wr-space-md) | .wr-file-upload__zone |
--wr-file-upload-zone-padding | var(--wr-space-xl) | .wr-file-upload__zone |
--wr-file-upload-zone-radius | var(--wr-border-radius-base) | .wr-file-upload__zone |
Dependencies
| Built on | Form |
|---|
See also
Component Image CropperCrop an image and get the result as a Blob.Pipe wrBytesShow a byte count as kB, MB or GB.Component ProgressA bar that shows how far a task has got.Component Form FieldWraps a form control with a label, a hint and its error messages.Guide FormsBind ngwr controls to any Angular form and show their errors.Component FormA plain layout wrapper for a label, a control and its error.