File Input

Files picked, dropped or pasted — chosen, never uploaded — as a File[] for Signal Forms; those that break a rule kept out, with every reason.

FormsExperimental

Usage

Usage

Drop or paste files here

import { Component, ViewEncapsulation } from '@angular/core';import {  ScFileInput,  ScFileInputDropzone,  ScFileInputItem,  ScFileInputItemPreview,  ScFileInputItemRemove,  ScFileInputItemSize,  ScFileInputList,  ScFileInputStatus,

Anatomy

The root writes the native picker itself (hidden); the trigger opens it, the dropzone takes drops and pastes, the list shows the files. Each part is optional but the root — a trigger alone is an upload button.

import { ScFileInput, ScFileInputDropzone, ScFileInputItem, ScFileInputItemPreview, ScFileInputItemRemove, ScFileInputItemSize, ScFileInputList, ScFileInputStatus, ScFileInputTrigger } from '@semantic-components/ui';
<div scFileInput #files="scFileInput" multiple [formField]="form.files">  <div scFileInputDropzone>    <button scFileInputTrigger>Browse files</button>  </div>  <ul scFileInputList aria-label="Chosen files">    @for (file of files.value(); track file) {      <li scFileInputItem [file]="file">        <span scFileInputItemPreview><svg siFileIcon></svg></span>        {{ file.name }}        <span scFileInputItemSize></span>        <button scFileInputItemRemove>…</button>      </li>    }  </ul>  <div scFileInputStatus>…</div></div>

Rules

With multiple, files are added to those there; without it, a new one replaces it. accept (MIME types, wildcards, extensions), minSize, maxSize, maxFiles (in all) and your validate keep files out: rejections() lists them with every reason — file-type, file-too-large, file-too-small, too-many-files, or yours — until the next pick, drop or paste. Uploading is yours. In a form, an empty list is not empty to Signal Forms' required(): use minLength(path, 1).

Keyboard

KeyDoes
Enter / SpaceOn the trigger: opens the picker
Tab Into the list: one stop, the last file focused
↑↓ / HomeEndBetween the files
Delete / Backspace Removes the file focused; focus on to the next (the trigger after the last)
Ctrl + V In the dropzone (or your paste target): pasted files are added; text is left alone

Accessibility

  • The trigger is the way in, by pointer and keyboard; the dropzone is not a control. In a field, the label opens the picker, and names the trigger with its own text.
  • The native picker is hidden from the Tab order and from screen readers, and named by the first trigger (aria-labelledby): a form control with no label is an error to checkers such as WAVE, hidden or not.
  • Name the list, and each remove button after its file; the remove buttons stay out of the Tab order (Delete does it).
  • scFileInputStatus is a polite live region: write in it, from lastChange(), what was added, removed or kept out.
  • Thumbnails are decorative: the name is beside them.

Examples

Upload button

No file chosen
import { Component, ViewEncapsulation } from '@angular/core';import { ScFileInput, ScFileInputTrigger } from '@semantic-components/ui';import { SiUploadIcon } from '@semantic-icons/lucide-icons';
/** Only a trigger — no dropzone, no list: one file, its name beside it. */@Component({  selector: 'app-upload-button-file-input-demo',  imports: [ScFileInput, ScFileInputTrigger, SiUploadIcon],  template: `    <div scFileInput #files="scFileInput" class="flex-row items-center">

Accepted types

Images or PDFs

import { Component, ViewEncapsulation } from '@angular/core';import {  ScFileInput,  ScFileInputDropzone,  ScFileInputItem,  ScFileInputItemPreview,  ScFileInputItemRemove,  ScFileInputItemSize,  ScFileInputList,  ScFileInputTrigger,

Limits

Up to 3 files, 5 MB each

import { Component, ViewEncapsulation } from '@angular/core';import {  ScFileInput,  ScFileInputDropzone,  ScFileInputItem,  ScFileInputItemPreview,  ScFileInputItemRemove,  ScFileInputItemSize,  ScFileInputList,  ScFileInputTrigger,

One file

One PDF

import { Component, ViewEncapsulation } from '@angular/core';import {  ScFileInput,  ScFileInputDropzone,  ScFileInputItem,  ScFileInputItemPreview,  ScFileInputItemRemove,  ScFileInputItemSize,  ScFileInputList,  ScFileInputTrigger,

Validation

Each file once

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScFileInput,  ScFileInputDropzone,  ScFileInputItem,  ScFileInputItemPreview,  ScFileInputItemRemove,  ScFileInputItemSize,  ScFileInputList,  ScFileInputTrigger,

Previews

Drop images here

import { Component, ViewEncapsulation } from '@angular/core';import {  ScFileInput,  ScFileInputDropzone,  ScFileInputItem,  ScFileInputItemPreview,  ScFileInputItemRemove,  ScFileInputList,  ScFileInputTrigger,} from '@semantic-components/ui';

Uploading

Drop files here

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScButton,  ScFileInput,  ScFileInputDropzone,  ScFileInputItem,  ScFileInputItemPreview,  ScFileInputItemRemove,  ScFileInputItemSize,  ScFileInputList,

Attachments

import { Component, ViewEncapsulation } from '@angular/core';import {  ScFileInput,  ScFileInputDropzone,  ScFileInputItem,  ScFileInputItemPreview,  ScFileInputItemRemove,  ScFileInputItemSize,  ScFileInputList,  ScFileInputTrigger,

Page-wide drop

Drag files anywhere on this page, or .

import { Component, ViewEncapsulation } from '@angular/core';import {  ScFileInput,  ScFileInputDropzone,  ScFileInputItem,  ScFileInputItemPreview,  ScFileInputItemRemove,  ScFileInputItemSize,  ScFileInputList,  ScFileInputTrigger,

Folders

Drop a folder here

import { Component, ViewEncapsulation } from '@angular/core';import {  ScFileInput,  ScFileInputDropzone,  ScFileInputItem,  ScFileInputItemPreview,  ScFileInputItemRemove,  ScFileInputItemSize,  ScFileInputList,  ScFileInputTrigger,

Camera

import { Component, ViewEncapsulation } from '@angular/core';import {  ScFileInput,  ScFileInputItem,  ScFileInputItemPreview,  ScFileInputItemRemove,  ScFileInputItemSize,  ScFileInputList,  ScFileInputTrigger,} from '@semantic-components/ui';

Form

Drop files here

A bill or a statement: images or PDFs.

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  FormField,  FormRoot,  form,  minLength,  validate,} from '@angular/forms/signals';import {  ScButton,

RTL

أفلت الملفات هنا

import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import {  ScFileInput,  ScFileInputDropzone,  ScFileInputItem,  ScFileInputItemPreview,  ScFileInputItemRemove,  ScFileInputItemSize,  ScFileInputList,

API reference

Each part takes class, merged over its own (cn: a later class wins). The look is the style's (fileInput: from its Empty and its Item); the trigger and the remove buttons are the style's buttons (variant, size).

PartSelectorDescription
ScFileInputdiv[scFileInput] The root: the value, the rules, the native picker (hidden). exportAs scFileInput: open(), add(), remove(), clear(), focus(), rejections(), lastChange().
ScFileInputTriggerbutton[scFileInputTrigger] Opens the picker. In a field, the first takes the field's id: the label opens it.
ScFileInputDropzone[scFileInputDropzone] Takes drops (here, or the whole page) and pastes. data-dragging, data-drag-accept, data-drag-reject.
ScFileInputListul[scFileInputList] The files: one Tab stop, arrows between them, Delete removes. Name it.
ScFileInputItemli[scFileInputItem] A file: [file]. Focusable.
ScFileInputItemPreview[scFileInputItemPreview] An image's thumbnail, or your icon.
ScFileInputItemSize[scFileInputItemSize] Its size, in the app's language (formatFileSize).
ScFileInputItemRemovebutton[scFileInputItemRemove] Takes its file out; out of the Tab order. Name it.
ScFileInputStatus[scFileInputStatus] A polite live region (sr-only): your words, from lastChange().
InputTypeDefaultDescription
valueFile[][] Two-way, or [formField].
multiplebooleanfalse Added to those there; without it, a new one replaces it.
acceptstring | string[]'' MIME types, wildcards, extensions.
minSize, maxSizenumber— Per file, in bytes.
maxFilesnumber— The most files, in all.
validate(file, { accepted }) => string | null— Your rule: a reason to keep the file out.
directorybooleanfalse A folder picked (fileRelativePath for each file).
capture'environment' | 'user' | booleanfalse The camera on a phone.
disabled, required, invalid, touchedbooleanfalse Bound by [formField].
InputTypeDefaultDescription
target'self' | 'document''self' Where drops are taken: on it, or anywhere on the page.
pasteTarget'self' | 'document' | HTMLElement | null'self' Where pasted files are taken.