Skip to main content

File drop

Drag-and-drop or browse for files, form-associated.

<mm-file-drop name="manifest" label="dbt manifest" accept=".json" max-size="10 MB" required></mm-file-drop>
<mm-file-drop name="seeds" label="CSV seeds" accept=".csv,text/csv" max-size="10 MB" multiple></mm-file-drop>

Guidance​

File drops take one or more files for upload, such as a dbt manifest.json or a CSV seed. A dashed zone accepts dragged files and always offers a visible "browse" button that opens the native file picker, so the control works fully from the keyboard. While files are dragged over it, the zone turns sunken and its text changes, so the state never relies on colour alone.

Chosen files are listed with their name, their size in tabular figures and a remove button. Files that are too large or of the wrong type are not added; a sentence names the file and the limit. The element is form-associated: each file is appended to the form's FormData under name, required blocks submission until a file is chosen, and form reset clears the list.

Properties​

PropertyAttributeTypeDefaultDescription
acceptacceptstring''Accepted types, as for the native input: extensions (.json) and MIME types (text/csv, image/*).
multiplemultiplebooleanfalseAllows more than one file.
maxSizemax-sizenumber0Largest file allowed, in bytes or with a unit (10 MB, 500KB). Larger files are not added.
loadingloadingbooleanfalseShows a spinner on each file and blocks changes while the files upload.
filesFile[][]The chosen files.
valueFile[]The chosen files (alias of files).
labellabelstring''Field label. Rendered above the control unless hide-label, and always the accessible name.
helphelpstring''Help text under the control.
errorerrorstring''Error text: a sentence saying what to fix. Shows the crimson border, an icon and sets aria-invalid.
hideLabelhide-labelbooleanfalseHides the label visually; it stays the accessible name.
optionaloptionalbooleanfalseMarks the field as optional, in words.
namenamestring''Name submitted with the form.
disableddisabledbooleanfalseDisables the control and excludes it from submission.
requiredrequiredbooleanfalseRequires a value before the form submits.
formHTMLFormElement | null
validityValidityState
validationMessagestring
willValidateboolean
isDisabledbooleanTrue when disabled directly or by a disabled ancestor fieldset.

Methods​

MethodDescription
browse()Opens the native file picker.
addFiles()Validates and adds files as if they had been dropped. Returns the rejections.
removeFile()Removes one chosen file.
formResetCallback()Restore the initial value when the owning form resets.

Events​

EventDetailDescription
mm-inputCustomEvent<File[]>The chosen files changed; fired before mm-change.
mm-changeCustomEvent<File[]>The chosen files changed (added by drop or browse, or removed).
mm-rejectCustomEvent<FileRejection[]>One or more files were not added, with the reason for each.
changeEventNative change event, re-dispatched from the host when the files change.
inputInputEvent

CSS parts​

PartDescription
zoneThe dashed drop zone.
browseThe browse button.
listThe list of chosen files.
fileOne chosen file row.
removeA remove button.

Examples​

Every state of mm-file-drop in Storybook, with keyboard and screen reader tests.