File Input

2.8.0Beta

The File Input component renders a single-file form field with QDS input styling and file validation support.

import {FileInputModule} from "@qualcomm-ui/angular/file-input"

Overview

The File Input component supports both click-to-browse and drag-and-drop interactions for a single file input. An advanced file upload component is currently in development and will support multi-file lists, async uploads, previews, and rejected-file workflows.

Examples

Simple

The simple <q-file-input> component bundles the label, input-like control, display text, clear trigger, hidden input, and error text into one component.

Select a file
<q-file-input
  class="w-full max-w-sm"
  label="Upload file"
  placeholder="Select a file"
  startIcon="Upload"
/>

Composite

Use the composite API when layout or individual parts need explicit control.

Select a PDF
<div
  class="w-full max-w-sm"
  q-file-input-root
  startIcon="Upload"
  [accept]="['.pdf']"
>
  <label q-file-input-label>Upload agreement</label>
  <div q-file-input-control>
    <span placeholder="Select a PDF" q-file-input-display></span>
  </div>
  <input q-file-input-hidden-input />
</div>

Sizes

The File Input component supports three size variants: sm, md (default), and lg.

Select a file
Select a file
Select a file
<div class="flex w-full flex-col items-center gap-6">
  <q-file-input
    class="w-full max-w-sm"
    label="Upload file (Small)"
    placeholder="Select a file"
    size="sm"
    startIcon="Upload"
  />

  <q-file-input
    class="w-full max-w-sm"
    label="Upload file (Medium)"
    placeholder="Select a file"
    size="md"
    startIcon="Upload"
  />

  <q-file-input
    class="w-full max-w-sm"
    label="Upload file (Large)"
    placeholder="Select a file"
    size="lg"
    startIcon="Upload"
  />
</div>

Errors

Set invalid and errorText for field-level validation messages. Configure file validation with properties such as accept, maxFileSize, and validate.

Select a PDF
Upload a PDF file under 5 MB
<q-file-input
  class="w-full max-w-sm"
  errorText="Upload a PDF file under 5 MB"
  invalid
  label="Tax document"
  placeholder="Select a PDF"
  required
  startIcon="Upload"
  [accept]="['.pdf']"
  [maxFileSize]="5 * 1024 * 1024"
/>

Disabled

Set disabled on the simple component or root directive to prevent file selection and clearing.

Select a file
<div class="flex w-full max-w-sm flex-col gap-4">
  <label
    label="I agree to the terms and conditions"
    q-checkbox
    [(ngModel)]="agreed"
  ></label>
  <q-file-input
    label="Upload approval"
    placeholder="Select a file"
    startIcon="Upload"
    [disabled]="!agreed()"
  />
</div>

API

<q-file-input>

The <q-file-input> component extends the q-file-input-root directive with the following properties:

PropTypeDefault
When true, renders a clear button that resets the selected file on click. The button only appears when a file has been selected.
boolean
true
Optional error message that describes the element when invalid is true.
string
Optional label describing the file input. This element is automatically associated with the hidden file input for accessibility.
string
Text shown when no file has been selected.
string
Type
boolean
Description
When true, renders a clear button that resets the selected file on click. The button only appears when a file has been selected.
Type
string
Description
Optional error message that describes the element when invalid is true.
Type
string
Description
Optional label describing the file input. This element is automatically associated with the hidden file input for accessibility.
Type
string
Description
Text shown when no file has been selected.

Composite API

q-file-input-root

PropTypeDefault
The accept file types.
FileAcceptType
The controlled accepted files.
Array<File>
Whether to allow drag and drop in the dropzone element.
boolean
true
The default camera to use when capturing media (for mobile only).
| 'user'
| 'environment'
The default accepted files when rendered. Use when you don't need to control the accepted files of the input.
Array<File>
The document's text/writing direction.
'ltr' | 'rtl'
Whether to accept directories, only works in webkit browsers.
boolean
Whether the file input is disabled.
boolean
lucide-angular icon, positioned after the input.
| string
| LucideIconData
A root node to correctly resolve the Document in custom environments. i.e., Iframes, Electron.
() =>
| Node
| ShadowRoot
| Document
id attribute. If omitted, a unique identifier will be generated for accessibility.
string
Whether the file input is invalid. When true, applies error styling and shows the error text. Use for form-level validation. Per-file rejection errors are handled automatically.
boolean
The locale for formatting file sizes.
string
The maximum number of files.
number
1
The maximum file size in bytes.
number
Infinity
The minimum file size in bytes.
number
0
The name of the underlying file input.
string
Whether to prevent the drop event on the document.
boolean
true
Whether the file input is required.
boolean
The size of the input field and its elements. Governs properties like font size, item padding, and icon sizes.
| 'sm'
| 'md'
| 'lg'
'md'
lucide-angular icon, positioned before the input.
| string
| LucideIconData
Transforms accepted files asynchronously after validation. Use for compression, resizing, format conversion, or other processing before setting final state.
(
files: Array<File>,
) => Promise<Array<File>>
The localized messages to use.
{
listLabel?: string
}
Function to validate a file.
FileValidateFn
Callback fired when the file is accepted.
{
files: Array<File>
}
Callback fired when the value changes, whether accepted or rejected.
FileDetails
Callback fired when the file is rejected.
FileRejectDetails
Type
FileAcceptType
Description
The accept file types.
Type
Array<File>
Description
The controlled accepted files.
Type
boolean
Description
Whether to allow drag and drop in the dropzone element.
Type
| 'user'
| 'environment'
Description
The default camera to use when capturing media (for mobile only).
Type
Array<File>
Description
The default accepted files when rendered. Use when you don't need to control the accepted files of the input.
Type
'ltr' | 'rtl'
Description
The document's text/writing direction.
Type
boolean
Description
Whether to accept directories, only works in webkit browsers.
Type
boolean
Description
Whether the file input is disabled.
Type
| string
| LucideIconData
Description
lucide-angular icon, positioned after the input.
Type
() =>
| Node
| ShadowRoot
| Document
Description
A root node to correctly resolve the Document in custom environments. i.e., Iframes, Electron.
Type
string
Description
id attribute. If omitted, a unique identifier will be generated for accessibility.
Type
boolean
Description
Whether the file input is invalid. When true, applies error styling and shows the error text. Use for form-level validation. Per-file rejection errors are handled automatically.
Type
string
Description
The locale for formatting file sizes.
Type
number
Description
The maximum number of files.
Type
number
Description
The maximum file size in bytes.
Type
number
Description
The minimum file size in bytes.
Type
string
Description
The name of the underlying file input.
Type
boolean
Description
Whether to prevent the drop event on the document.
Type
boolean
Description
Whether the file input is required.
Type
| 'sm'
| 'md'
| 'lg'
Description
The size of the input field and its elements. Governs properties like font size, item padding, and icon sizes.
Type
| string
| LucideIconData
Description
lucide-angular icon, positioned before the input.
Type
(
files: Array<File>,
) => Promise<Array<File>>
Description
Transforms accepted files asynchronously after validation. Use for compression, resizing, format conversion, or other processing before setting final state.
Type
{
listLabel?: string
}
Description
The localized messages to use.
Type
FileValidateFn
Description
Function to validate a file.
Type
{
files: Array<File>
}
Description
Callback fired when the file is accepted.
Type
FileDetails
Description
Callback fired when the value changes, whether accepted or rejected.
Type
FileRejectDetails
Description
Callback fired when the file is rejected.

q-file-input-label

PropType
id attribute. If omitted, a unique identifier will be generated for accessibility.
string
Type
string
Description
id attribute. If omitted, a unique identifier will be generated for accessibility.

q-file-input-control

PropType
Whether to disable the click event on the dropzone
boolean
string
Type
boolean
Description
Whether to disable the click event on the dropzone
Type
string

q-file-input-display

PropType
Text shown when no file has been selected.
string
Type
string
Description
Text shown when no file has been selected.

q-file-input-clear-trigger

q-file-input-hidden-input

PropType
id attribute. If omitted, a unique identifier will be generated for accessibility.
string
Type
string
Description
id attribute. If omitted, a unique identifier will be generated for accessibility.

q-file-input-error-text

PropType
Optional error indicator icon.
| string
| LucideIconData
string
Type
| string
| LucideIconData
Description
Optional error indicator icon.
Type
string
Last updated on by Ryan Bower