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>Use the React primitive adapter when Dropzone state participates in React rendering.
import { Dropzone } from "@starwind-ui/react/dropzone";
export function Example() { return ( <Dropzone.Root> <Dropzone.Input /> <Dropzone.UploadIndicator>Drop files here</Dropzone.UploadIndicator> <Dropzone.LoadingIndicator>Uploading...</Dropzone.LoadingIndicator> <Dropzone.FilesList /> </Dropzone.Root> );}Use the Vue components to build Dropzone.
<script setup lang="ts">import Dropzone from "@starwind-ui/vue/dropzone";</script>
<template> <Dropzone.Root> <Dropzone.Input /> <Dropzone.UploadIndicator>Drop files here</Dropzone.UploadIndicator> <Dropzone.LoadingIndicator>Uploading...</Dropzone.LoadingIndicator> <Dropzone.FilesList /> </Dropzone.Root></template>Use the Svelte components to build Dropzone.
<script lang="ts"> import { Dropzone } from "@starwind-ui/svelte/dropzone";</script>
<Dropzone.Root> <Dropzone.Input /> <Dropzone.UploadIndicator>Drop files here</Dropzone.UploadIndicator> <Dropzone.LoadingIndicator>Uploading...</Dropzone.LoadingIndicator> <Dropzone.FilesList /></Dropzone.Root>Render the Dropzone data-sw-* contract yourself, then initialize createDropzone.
<label data-sw-dropzone role="button"> <input data-sw-dropzone-input type="file" tabindex="-1" class="sr-only" /> <div data-sw-dropzone-upload-indicator>Drop files here</div> <div data-sw-dropzone-loading-indicator hidden>Uploading...</div> <div data-sw-dropzone-files-list></div></label>
<script type="module"> import { createDropzone } from "@starwind-ui/runtime/dropzone";
const root = document.querySelector("[data-sw-dropzone]"); if (root) { createDropzone(root); }</script>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
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.
isUploadingsetUploading
- Runtime / HTML
Use data-is-uploading for initial state and call setUploading for later updates.
data-is-uploadingsetUploading
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
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
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.
isUploadingsetUploading
- Runtime / HTML
Use data-is-uploading for initial state and call setUploading for later updates.
data-is-uploadingsetUploading
Data Attributes
Runtime hooks
State
Metadata
Input
The native input synchronized by Dropzone.
- Default element
- input
- Discovery hook
- data-sw-dropzone-input
- Role
- -
Props
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
Metadata
Upload Indicator
Upload progress indicator shown by Dropzone.
- Default element
- div
- Discovery hook
- data-sw-dropzone-upload-indicator
- Role
- -
Props
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.
isUploadingsetUploading
- Runtime / HTML
Use data-is-uploading for initial state and call setUploading for later updates.
data-is-uploadingsetUploading
State
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.
isUploadingsetUploading
- Runtime / HTML
Use data-is-uploading for initial state and call setUploading for later updates.
data-is-uploadingsetUploading
Data Attributes
Runtime hooks
State
Loading Indicator
Loading indicator shown by Dropzone.
- Default element
- div
- Discovery hook
- data-sw-dropzone-loading-indicator
- Role
- -
Props
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.
isUploadingsetUploading
- Runtime / HTML
Use data-is-uploading for initial state and call setUploading for later updates.
data-is-uploadingsetUploading
State
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.
isUploadingsetUploading
- Runtime / HTML
Use data-is-uploading for initial state and call setUploading for later updates.
data-is-uploadingsetUploading
Data Attributes
Runtime hooks
State
Files List
Lists the selected files for Dropzone.
- Default element
- div
- Discovery hook
- data-sw-dropzone-files-list
- Role
- -
Data Attributes
Runtime hooks
State
Runtime API
- Factory
createDropzone- Import
@starwind-ui/runtime/dropzone- Root hook
- root
data-sw-dropzone - Option props
- disabled, isUploading, onFilesChange
Option Lifecycles
| Option | Lifecycle |
|---|---|
| disabled | setter-backed |
| isUploading | setter-backed |
| onFilesChange | constructor-only |
Runtime Setters
Form Participation
| Fact | Value |
|---|---|
| Form props | accept, multiple, name, required |
| Hidden input | input (file) |
| Field integration | No |
Related Styled Components
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.