Dropzone

Dropzone is a component used for uploading files via drag and drop.

Usage

import { Dropzone } from "@yamada-ui/react"
<Dropzone.Root>
  <Dropzone.Title />
  <Dropzone.Description />
  <Dropzone.Accept>
    <Dropzone.Icon />
  </Dropzone.Accept>
  <Dropzone.Reject>
    <Dropzone.Icon />
  </Dropzone.Reject>
  <Dropzone.Idle>
    <Dropzone.Icon />
  </Dropzone.Idle>
</Dropzone.Root>

Change Variant

Change Size

Allow Multiple Selection

To allow multiple selection, set multiple to true.

Specify File Extensions

To specify file extensions, set accept to an array of strings or an object.

We also provide easy-to-use constants like IMAGE_ACCEPT_TYPE and PDF_ACCEPT_TYPE.

Specify Maximum File Size

To specify the maximum file size, set maxSize to a number (bytes).

Specify Maximum Number of Uploadable Files

To specify the maximum number of uploadable files, set maxFiles to a number.

Display According to Status

To control the display based on whether the file is accepted or rejected, use DropzoneAccept, DropzoneReject, DropzoneIdle.

  • DropzoneAccept: A component displayed when a file is accepted.
  • DropzoneReject: A component displayed when a file is rejected.
  • DropzoneIdle: A component displayed when in idle state.

Handle Dropped Event

To handle the selection event, use onDrop.

Handle Only Accepted Files

To handle only accepted files, use onDropAccepted.

Handle Only Rejected Files

To handle only rejected files, use onDropRejected.

Change Border Color

To change the border color, set focusBorderColor or errorBorderColor to a color.

Disable

To disable, set disabled to true.

Read-Only

To read-only, set readOnly to true.

Invalid

To set invalid state, set invalid to true.

File is required.

Use Loading Animation

To use a loading animation, set loading to true.

Control

Props

Accessibility

If you are not using Field.Root, set aria-label or aria-labelledby to Dropzone.Root.

<Dropzone.Root aria-label="Upload file">
  <Text>Drag file here or click to select file</Text>
</Dropzone.Root>
<VStack gap="sm">
  <Text as="h3" id="label">
    Upload file
  </Text>

  <Dropzone.Root aria-labelledby="label">
    <Text>Drag file here or click to select file</Text>
  </Dropzone.Root>
</VStack>

Keyboard Navigation

KeyDescriptionState
Space, EnterOpens the file selection dialog.-

ARIA Roles and Attributes

ComponentRoles and AttributesUsage
Dropzone.Rootrole="presentation"Indicates that this is a presentation.
aria-disabledSets to "true" when disabled, readOnly, or loading is set.
inputaria-labelledbySets the id of the associated Dropzone.Root.
aria-disabledSets to "true" when disabled is set.
aria-invalidSets to "true" when invalid is set.
aria-readonlySets to "true" when readOnly is set.
aria-requiredSets to "true" when required is set.
aria-describedbyIf Dropzone.Root is within a Field.Root and Field.Root has an errorMessage, helperMessage, or a Field.ErrorMessage, Field.HelperMessage, sets its id.

Similar Components

FileButton

FileButton is a button component used for users to select files.

FileInput

FileInput is a component used for users to select files.

Checkbox

Checkbox is a component used for allowing users to select multiple values from multiple options.

ColorSelector

ColorSelector is a component used by the user to select a color.

Editable

Editable is a component used to obtain inline editable text input.

Field

Field is a component used to group form elements with label, helper message, error message, etc.

Fieldset

Fieldset is a component used to group elements such as legends, helper messages, and error messages in a fieldset element.

Form

Form is a component used to group multiple form elements.

Uses Components & Hooks