Dropzone
Dropzone
is a component used for uploading files via drag and drop.
Drag file here or click to select file
<Dropzone.Root>
<Text>Drag file here or click to select file</Text>
</Dropzone.Root>
Usage
import { Dropzone } from "@yamada-ui/react"
import { Dropzone } from "@/components/ui"
import { Dropzone } from "@workspaces/ui"
<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>
Dropzone
internally uses react-dropzone.Change Variant
Drag file here or click to select file
Drag file here or click to select file
Drag file here or click to select file
<VStack>
<For each={["dashed", "solid", "panel"]}>
{(variant, index) => (
<Dropzone.Root key={index} variant={variant}>
<Text>Drag file here or click to select file</Text>
</Dropzone.Root>
)}
</For>
</VStack>
Change Size
Drag file here or click to select file
Drag file here or click to select file
Drag file here or click to select file
Drag file here or click to select file
<VStack>
<For each={["xs", "sm", "md", "lg"]}>
{(size, index) => (
<Dropzone.Root key={index} size={size}>
<Text>Drag file here or click to select file</Text>
</Dropzone.Root>
)}
</For>
</VStack>
Allow Multiple Selection
To allow multiple selection, set multiple
to true
.
Drag files here or click to select files
<Dropzone.Root multiple>
<Text>Drag files here or click to select files</Text>
</Dropzone.Root>
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
.
Drag image here or click to select image
Drag image here or click to select image
<VStack>
<Dropzone.Root accept={Dropzone.IMAGE_ACCEPT_TYPE}>
<Text>Drag image here or click to select image</Text>
</Dropzone.Root>
<Dropzone.Root accept={{ "image/*": [] }}>
<Text>Drag image here or click to select image</Text>
</Dropzone.Root>
</VStack>
Specify Maximum File Size
To specify the maximum file size, set maxSize
to a number (bytes).
Drag file here or click to select file
Attach as many files as you like, each file should not exceed 5mb
<Dropzone.Root maxSize={3 * 1024 ** 2}>
<VStack alignItems="center" gap="xs">
<Dropzone.Title>Drag file here or click to select file</Dropzone.Title>
<Dropzone.Description>
Attach as many files as you like, each file should not exceed 5mb
</Dropzone.Description>
</VStack>
</Dropzone.Root>
Specify Maximum Number of Uploadable Files
To specify the maximum number of uploadable files, set maxFiles
to a number.
Drag file here or click to select file
Attach as many files as you like, can upload up to 3 files
<Dropzone.Root maxFiles={3} multiple>
<VStack alignItems="center" gap="xs">
<Dropzone.Title>Drag file here or click to select file</Dropzone.Title>
<Dropzone.Description>
Attach as many files as you like, can upload up to 3 files
</Dropzone.Description>
</VStack>
</Dropzone.Root>
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.
Drag images here or click to select files
Attach as many files as you like, each file should not exceed 5mb
<Dropzone.Root accept={Dropzone.IMAGE_ACCEPT_TYPE} maxSize={3 * 1024 ** 2}>
<HStack>
<Dropzone.Accept>
<Dropzone.Icon as={UploadIcon} />
</Dropzone.Accept>
<Dropzone.Reject>
<Dropzone.Icon as={XIcon} />
</Dropzone.Reject>
<Dropzone.Idle>
<Dropzone.Icon as={ImageIcon} />
</Dropzone.Idle>
<VStack gap="xs">
<Dropzone.Title>Drag images here or click to select files</Dropzone.Title>
<Dropzone.Description>
Attach as many files as you like, each file should not exceed 5mb
</Dropzone.Description>
</VStack>
</HStack>
</Dropzone.Root>
Handle Dropped Event
To handle the selection event, use onDrop
.
Drag images here or click to select files
Attach as many files as you like, each file should not exceed 5mb
<Dropzone.Root
accept={Dropzone.IMAGE_ACCEPT_TYPE}
maxSize={3 * 1024 ** 2}
onDrop={(acceptedFiles, fileRejections) =>
console.log("dropped", acceptedFiles, fileRejections)
}
>
<HStack>
<Dropzone.Accept>
<Dropzone.Icon as={UploadIcon} />
</Dropzone.Accept>
<Dropzone.Reject>
<Dropzone.Icon as={XIcon} />
</Dropzone.Reject>
<Dropzone.Idle>
<Dropzone.Icon as={ImageIcon} />
</Dropzone.Idle>
<VStack gap="xs">
<Dropzone.Title>Drag images here or click to select files</Dropzone.Title>
<Dropzone.Description>
Attach as many files as you like, each file should not exceed 5mb
</Dropzone.Description>
</VStack>
</HStack>
</Dropzone.Root>
Handle Only Accepted Files
To handle only accepted files, use onDropAccepted
.
Drag images here or click to select files
Attach as many files as you like, each file should not exceed 5mb
<Dropzone.Root
accept={Dropzone.IMAGE_ACCEPT_TYPE}
maxSize={3 * 1024 ** 2}
onDropAccepted={(files) => console.log("accepted", files)}
>
<HStack>
<Dropzone.Accept>
<Dropzone.Icon as={UploadIcon} />
</Dropzone.Accept>
<Dropzone.Reject>
<Dropzone.Icon as={XIcon} />
</Dropzone.Reject>
<Dropzone.Idle>
<Dropzone.Icon as={ImageIcon} />
</Dropzone.Idle>
<VStack gap="xs">
<Dropzone.Title>Drag images here or click to select files</Dropzone.Title>
<Dropzone.Description>
Attach as many files as you like, each file should not exceed 5mb
</Dropzone.Description>
</VStack>
</HStack>
</Dropzone.Root>
Handle Only Rejected Files
To handle only rejected files, use onDropRejected
.
Drag images here or click to select files
Attach as many files as you like, each file should not exceed 5mb
<Dropzone.Root
accept={Dropzone.IMAGE_ACCEPT_TYPE}
maxSize={3 * 1024 ** 2}
onDropRejected={(files) => console.log("rejected", files)}
>
<HStack>
<Dropzone.Accept>
<Dropzone.Icon as={UploadIcon} />
</Dropzone.Accept>
<Dropzone.Reject>
<Dropzone.Icon as={XIcon} />
</Dropzone.Reject>
<Dropzone.Idle>
<Dropzone.Icon as={ImageIcon} />
</Dropzone.Idle>
<VStack gap="xs">
<Dropzone.Title>Drag images here or click to select files</Dropzone.Title>
<Dropzone.Description>
Attach as many files as you like, each file should not exceed 5mb
</Dropzone.Description>
</VStack>
</HStack>
</Dropzone.Root>
Change Border Color
To change the border color, set focusBorderColor
or errorBorderColor
to a color.
Drag file here or click to select file
Drag file here or click to select file
<VStack>
<Dropzone.Root focusBorderColor="green.500">
<Text>Drag file here or click to select file</Text>
</Dropzone.Root>
<Dropzone.Root errorBorderColor="orange.500" invalid>
<Text>Drag file here or click to select file</Text>
</Dropzone.Root>
</VStack>
Disable
To disable, set disabled
to true
.
Drag file here or click to select file
Drag file here or click to select file
<VStack>
<Dropzone.Root disabled>
<Text>Drag file here or click to select file</Text>
</Dropzone.Root>
<Field.Root disabled label="Upload file">
<Dropzone.Root>
<Text>Drag file here or click to select file</Text>
</Dropzone.Root>
</Field.Root>
</VStack>
Read-Only
To read-only, set readOnly
to true
.
Drag file here or click to select file
Drag file here or click to select file
<VStack>
<Dropzone.Root readOnly>
<Text>Drag file here or click to select file</Text>
</Dropzone.Root>
<Field.Root label="Upload file" readOnly>
<Dropzone.Root>
<Text>Drag file here or click to select file</Text>
</Dropzone.Root>
</Field.Root>
</VStack>
Invalid
To set invalid state, set invalid
to true
.
Drag file here or click to select file
Drag file here or click to select file
<VStack>
<Dropzone.Root invalid>
<Text>Drag file here or click to select file</Text>
</Dropzone.Root>
<Field.Root errorMessage="File is required." invalid label="Upload file">
<Dropzone.Root>
<Text>Drag file here or click to select file</Text>
</Dropzone.Root>
</Field.Root>
</VStack>
Use Loading Animation
To use a loading animation, set loading
to true
.
Drag file here or click to select file
Drag file here or click to select file
Drag file here or click to select file
<VStack>
<Dropzone.Root loading>
<Text>Drag file here or click to select file</Text>
</Dropzone.Root>
<Dropzone.Root loading loadingScheme="grid">
<Text>Drag file here or click to select file</Text>
</Dropzone.Root>
<Dropzone.Root loading loadingProps={{ color: "blue" }}>
<Text>Drag file here or click to select file</Text>
</Dropzone.Root>
</VStack>
Control
Drag file here or click to select file
const openRef = useRef<() => void>(noop)
return (
<VStack>
<Button onClick={() => openRef.current()}>Select file</Button>
<Dropzone.Root openRef={openRef}>
<Text>Drag file here or click to select file</Text>
</Dropzone.Root>
</VStack>
)
Props
Accessibility
Currently, this section is being updated due to the migration of v2.