File Upload

Material Design 3-styled file upload web component (lit-material-file-upload) — drag-and-drop or click-to-browse, single or multiple files.

  • 2.6 KB gzipped
  • @lit-material/file-upload 0.0.3
  • Renders on the server

Example

Install

npm install @lit-material/file-upload @lit-material/tokens
import "@lit-material/file-upload";

Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide

API

<lit-material-file-upload>

A drag-and-drop (or click-to-browse) file picker, for a single file or (with multiple) several — mirroring the native <input type="file" multiple> attribute rather than being two separate components for the two cases, the same way a native file input handles both with one element. The actual picking is a real <input type="file">, visually hidden but still in the tab order and keyboard-operable (Enter/Space opens the native picker) via the <label> wrapping it — no custom keyboard handling needed for that part at all.

Properties

PropertyAttributeTypeDefaultDescription
multiplemultiplebooleanfalse
acceptacceptstring""
disableddisabledbooleanfalse
labellabelstring""
namenamestring""
filesproperty onlyFile[]noneThe currently selected files. Assign to replace the selection programmatically.

Events

EventDescription
changeFires whenever the file selection changes (add or remove).

Slots

SlotDescription
defaultOverrides the dropzone's instructions text.

CSS parts

PartDescription
uploadThe outer container (also the drop target).
dropzoneThe clickable/draggable label surface.
inputThe native <input type="file">.
instructionsThe instructions text.
file-listThe <ul> of selected files. Only rendered once at least one file is selected.
file-rowOne file's row.
file-nameA file row's name.
file-sizeA file row's formatted size.
removeA file row's remove button.

Source on GitHub npm