Skip to main content

Starwind UI v3.7 is here with stable Vue and Svelte, the new Chart component, and full RTL support. Read the release notes

Dropzone Primitive

Use Dropzone to collect files by dropping them onto a page or opening a file picker. It checks the files against the limits you set.

Anatomy

Use the Astro primitive adapter to render Dropzone anatomy with the Runtime wiring included.

---
import { Dropzone } from "@starwind-ui/astro/dropzone";
---
<Dropzone.Root>
<Dropzone.Input />
<Dropzone.UploadIndicator>Drop files here</Dropzone.UploadIndicator>
<Dropzone.LoadingIndicator>Uploading...</Dropzone.LoadingIndicator>
<Dropzone.FilesList />
</Dropzone.Root>

Astro, React, Vue, and Svelte components use the same underlying interactions. Each framework has its own way to read and update state. See the examples and your installed packageโ€™s types for the available props and events. Plain HTML uses DOM events and Runtime methods.

API Reference

Root

The main element that owns the Dropzone Runtime instance.

Default element
label
Discovery hook
data-sw-dropzone
Role
button

Props

Prop Type Default Toggle
disabled boolean false
Description
Disables the Root part.
Kind
option
Targets
-
Full type
boolean
isUploading boolean false
Description
Controls whether Dropzone is uploading.
Kind
control
Targets
root, uploadIndicator, loadingIndicator
Full type
boolean
React

Use isUploading for controlled state.

  • isUploading
Astro

Use isUploading for initial state and call setUploading for later updates.

  • isUploading
  • setUploading
Runtime / HTML

Use data-is-uploading for initial state and call setUploading for later updates.

  • data-is-uploading
  • setUploading
onFilesChange (files: File[], details: DropzoneFilesChangeDetails) => void -
Description
Runs when selected files change for Dropzone.
Kind
callback
Targets
-
Full type
(files: File[], details: DropzoneFilesChangeDetails) => void
onFilesReject (files: File[], details: DropzoneFilesRejectDetails) => void -
Description
Runs when Dropzone does not keep dropped files because of accept or multiple.
Kind
callback
Targets
-
Full type
(files: File[], details: DropzoneFilesRejectDetails) => void

Events

Event Callback Value Toggle
filesChange onFilesChange files: File[]
Description
Fires when selected files change for Dropzone.
DOM event
starwind:files-change
Details type
DropzoneFilesChangeDetails
Timing
-
Cancelable
No
filesReject onFilesReject files: File[]
Description
Fires when Dropzone does not keep dropped files because of accept or multiple.
DOM event
starwind:files-reject
Details type
DropzoneFilesRejectDetails
Timing
-
Cancelable
No

State

State Type Props Toggle
uploading boolean isUploading
Description
Tracks whether Dropzone is uploading files.
Initial attribute
data-is-uploading
Runtime getter
getUploading
Runtime setter
setUploading
React

Use isUploading for controlled state.

  • isUploading
Astro

Use isUploading for initial state and call setUploading for later updates.

  • isUploading
  • setUploading
Runtime / HTML

Use data-is-uploading for initial state and call setUploading for later updates.

  • data-is-uploading
  • setUploading

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-dropzone - Marks the Root part so Starwind Runtime can find it.
State
Attribute Value Description
data-drag-active - Reflects the drag active state on the Root part.
data-has-files - Reflects the has files state on the Root part.
data-rejected - Reflects the rejected state on the Root part.
Metadata
Attribute Value Description
data-disabled - Reflects the disabled prop on the Root part.
data-is-uploading - Reflects the uploading prop on the Root part.

Input

The native input synchronized by Dropzone.

Default element
input
Discovery hook
data-sw-dropzone-input
Role
-

Props

Prop Type Default Toggle
accept string -
Description
Limits which file types can be selected.
Kind
attribute
Targets
input
Full type
string
multiple boolean -
Description
Allows multiple Dropzone values to be selected.
Kind
attribute
Targets
input
Full type
boolean
name string -
Description
Sets the submitted form field name.
Kind
attribute
Targets
input
Full type
string
required boolean -
Description
Marks the form control as required.
Kind
attribute
Targets
input
Full type
boolean

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-dropzone-input - Marks the Input part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-disabled - Reflects the disabled prop on the Input part.

Upload Indicator

Upload progress indicator shown by Dropzone.

Default element
div
Discovery hook
data-sw-dropzone-upload-indicator
Role
-

Props

Prop Type Default Toggle
isUploading boolean false
Description
Controls whether Dropzone is uploading.
Kind
control
Targets
root, uploadIndicator, loadingIndicator
Full type
boolean
React

Use isUploading for controlled state.

  • isUploading
Astro

Use isUploading for initial state and call setUploading for later updates.

  • isUploading
  • setUploading
Runtime / HTML

Use data-is-uploading for initial state and call setUploading for later updates.

  • data-is-uploading
  • setUploading

State

State Type Props Toggle
uploading boolean isUploading
Description
Tracks whether Dropzone is uploading files.
Initial attribute
data-is-uploading
Runtime getter
getUploading
Runtime setter
setUploading
React

Use isUploading for controlled state.

  • isUploading
Astro

Use isUploading for initial state and call setUploading for later updates.

  • isUploading
  • setUploading
Runtime / HTML

Use data-is-uploading for initial state and call setUploading for later updates.

  • data-is-uploading
  • setUploading

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-dropzone-upload-indicator - Marks the Upload Indicator part so Starwind Runtime can find it.
State
Attribute Value Description
data-is-uploading - Reflects the uploading state on the Upload Indicator part.

Loading Indicator

Loading indicator shown by Dropzone.

Default element
div
Discovery hook
data-sw-dropzone-loading-indicator
Role
-

Props

Prop Type Default Toggle
isUploading boolean false
Description
Controls whether Dropzone is uploading.
Kind
control
Targets
root, uploadIndicator, loadingIndicator
Full type
boolean
React

Use isUploading for controlled state.

  • isUploading
Astro

Use isUploading for initial state and call setUploading for later updates.

  • isUploading
  • setUploading
Runtime / HTML

Use data-is-uploading for initial state and call setUploading for later updates.

  • data-is-uploading
  • setUploading

State

State Type Props Toggle
uploading boolean isUploading
Description
Tracks whether Dropzone is uploading files.
Initial attribute
data-is-uploading
Runtime getter
getUploading
Runtime setter
setUploading
React

Use isUploading for controlled state.

  • isUploading
Astro

Use isUploading for initial state and call setUploading for later updates.

  • isUploading
  • setUploading
Runtime / HTML

Use data-is-uploading for initial state and call setUploading for later updates.

  • data-is-uploading
  • setUploading

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-dropzone-loading-indicator - Marks the Loading Indicator part so Starwind Runtime can find it.
State
Attribute Value Description
data-is-uploading - Reflects the uploading state on the Loading Indicator part.

Files List

Lists the selected files for Dropzone.

Default element
div
Discovery hook
data-sw-dropzone-files-list
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-dropzone-files-list - Marks the Files List part so Starwind Runtime can find it.
State
Attribute Value Description
data-has-files - Reflects the has files state on the Files List part.

Runtime API

Factory
createDropzone
Import
@starwind-ui/runtime/dropzone
Root hook
root data-sw-dropzone
Option props
disabled, isUploading, onFilesChange

Option Lifecycles

OptionLifecycle
disabledsetter-backed
isUploadingsetter-backed
onFilesChangeconstructor-only

Runtime Setters

Method Target Description
setDisabled prop: disabled Updates whether Dropzone is disabled from Runtime code.
setUploading prop: isUploading Updates whether Dropzone is uploading files from Runtime code.

Form Participation

FactValue
Form propsaccept, multiple, name, required
Hidden inputinput (file)
Field integrationNo
Component Relationship
Dropzone Direct primitive

Changelog

View version history v1.1.2 7 releases

v1.1.2

  • In Vue, this component now needs Vue 3.5.21 or newer.

v1.1.1

  • In Astro, an attribute that you set on a Dropzone part now wins over the part's own default for the same attribute, such as `role` or `aria-label`.

v1.1.0

  • Dropzone now rejects dropped files that do not match `accept`. A Dropzone without `multiple` keeps one file and rejects the other dropped files. Before, nothing happened and no event fired.
  • To get the rejected files, listen for the `starwind:files-reject` event on the Dropzone. In React and Svelte, use `onFilesReject`. In Vue, use `@files-reject`. The event gives you the rejected `files` and the drop `event`.
  • When Dropzone keeps none of the dropped files, the root gets a `data-rejected` attribute. It clears on the next accepted drop, file picker choice, `setFiles` call, or form reset. When a drop keeps some of the files, the event fires but the attribute is not set.
  • Screen readers do not announce a rejected drop. To tell screen reader users, show a message in a live region when the reject event fires.

v1.0.1

  • Kept file selection working when the file input is replaced or moves to another form.
  • Reduced the JavaScript loaded by Dropzone when it is used without Field.
  • Updated the shared setup file included with the Astro Primitive. Its public API and behavior are unchanged.

v1.0.0

  • This Primitive is now stable at version `1.0.0`. Its API and behavior stay the same as in the previous release.

v0.1.1

  • The React Primitive files that the CLI copies into your project are now marked with `"use client"`, so they stay client components in React server frameworks.

v0.1.0

  • First release. Dropzone handles drag and drop and works with its file input. It checks which files it accepts and fires file-change events.