--- title: Dropzone description: "`Dropzone` is a component used for uploading files via drag and drop." links: - style: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/dropzone/dropzone.style.ts - source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/dropzone - storybook: https://yamada-ui.github.io/yamada-ui?path=/story/components-dropzone--basic --- ```tsx Drag file here or click to select file ``` ## Usage ```tsx import { Dropzone } from "@yamada-ui/react" ``` ```tsx import { Dropzone } from "@/components/ui" ``` ```tsx import { Dropzone } from "@workspaces/ui" ``` ```tsx ``` :::note `Dropzone` internally uses [react-dropzone](https://react-dropzone.js.org/). ::: ### Change Variant ```tsx {(variant, index) => ( Drag file here or click to select file )} ``` ### Change Size ```tsx {(size, index) => ( Drag file here or click to select file )} ``` ### Allow Multiple Selection To allow multiple selection, set `multiple` to `true`. ```tsx Drag files here or click to select files ``` ### Specify File Extensions To specify file extensions, set `accept` to an array of strings or an [object](https://developer.mozilla.org/en-US/docs/Web/API/window/showOpenFilePicker). We also provide easy-to-use constants like `IMAGE_ACCEPT_TYPE` and `PDF_ACCEPT_TYPE`. ```tsx Drag image here or click to select image Drag image here or click to select image ``` ### Specify Maximum File Size To specify the maximum file size, set `maxSize` to a number (bytes). ```tsx Drag file here or click to select file Attach as many files as you like, each file should not exceed 5mb ``` ### Specify Maximum Number of Uploadable Files To specify the maximum number of uploadable files, set `maxFiles` to a number. ```tsx Drag file here or click to select file Attach as many files as you like, can upload up to 3 files ``` ### 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. ```tsx Drag images here or click to select files Attach as many files as you like, each file should not exceed 5mb ``` ### Handle Dropped Event To handle the selection event, use `onDrop`. :::warning Please note that it is always called regardless of whether the dropped file is accepted or rejected. ::: ```tsx console.log("dropped", acceptedFiles, fileRejections) } > Drag images here or click to select files Attach as many files as you like, each file should not exceed 5mb ``` ### Handle Only Accepted Files To handle only accepted files, use `onDropAccepted`. ```tsx console.log("accepted", files)} > Drag images here or click to select files Attach as many files as you like, each file should not exceed 5mb ``` ### Handle Only Rejected Files To handle only rejected files, use `onDropRejected`. ```tsx console.log("rejected", files)} > Drag images here or click to select files Attach as many files as you like, each file should not exceed 5mb ``` ### Change Border Color To change the border color, set `focusBorderColor` or `errorBorderColor` to a color. ```tsx Drag file here or click to select file Drag file here or click to select file ``` ### Disable To disable, set `disabled` to `true`. ```tsx Drag file here or click to select file Drag file here or click to select file ``` ### Read-Only To read-only, set `readOnly` to `true`. ```tsx Drag file here or click to select file Drag file here or click to select file ``` ### Invalid To set invalid state, set `invalid` to `true`. ```tsx Drag file here or click to select file Drag file here or click to select file ``` ### Use Loading Animation To use a loading animation, set `loading` to `true`. ```tsx Drag file here or click to select file Drag file here or click to select file Drag file here or click to select file ``` ### Control ```tsx const openRef = useRef<() => void>(noop) return ( Drag file here or click to select file ) ``` ## Props ### Dropzone.Root | Prop | Default | Type | Description | | ----------------------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `size` | `"sm"` | `"full" \| "lg" \| "md" \| "sm" \| "xs"` | The size of the component. | | `variant` | `"dashed"` | `"dashed" \| "panel" \| "plain" \| "solid"` | The variant of the component. | | `accept` | - | `Accept \| string[]` | Set accepted file types. | | `autoFocus` | `false` | `boolean` | Set to true to focus the root element on render. | | `disabled` | `false` | `boolean` | If `true`, the field will be disabled. | | `errorBorderColor` | - | `"-moz-initial" \| "ActiveBorder" \| "ActiveCaption" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" \| "amber.400" \| "amber.50" \| "amber.500" ...` | The border color when the input is invalid. | | `focusBorderColor` | - | `"-moz-initial" \| "ActiveBorder" \| "ActiveCaption" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" \| "amber.400" \| "amber.50" \| "amber.500" ...` | The border color when the input is focused. | | `getFilesFromEvent` | - | `DropzoneOptions["getFilesFromEvent"]` | Use this to provide a custom file aggregator. | | `inputProps` | - | `HTMLStyledProps<"input">` | Props for dropzone input element. | | `invalid` | `false` | `boolean` | If `true`, the field will be invalid. | | `loading` | `false` | `boolean` | If `true`, display the dropzone loading icon. | | `loadingProps` | - | `DropzoneLoadingProps` | Props for dropzone loading icon element. | | `loadingScheme` | `"oval"` | `LoadingScheme` | The loading scheme. | | `maxFiles` | `0` | `number` | Maximum accepted number of files. The default value is 0 which means there is no limitation to how many files are accepted. | | `maxSize` | `Infinity` | `number` | Maximum file size (in bytes). | | `minSize` | `0` | `number` | Minimum file size (in bytes). | | `multiple` | `false` | `boolean` | Allow drag and drop (or selection from the file dialog) of multiple files. | | `name` | - | `string` | The HTML `name` attribute used for forms. | | `noClick` | `false` | `boolean` | If true, disables click to open the native file selection dialog. | | `noDrag` | `false` | `boolean` | If true, disables drag and drop. | | `noDragEventsBubbling` | `false` | `boolean` | If true, stops drag event propagation to parents. | | `noKeyboard` | `false` | `boolean` | If true, disables `space` and `enter` to open the native file selection dialog. Note that it also stops tracking the focus state. | | `onDragEnter` | - | `DropzoneOptions["onDragEnter"]` | Callback for when the dragenter event occurs. | | `onDragLeave` | - | `DropzoneOptions["onDragLeave"]` | Callback for when the dragleave event occurs. | | `onDragOver` | - | `DropzoneOptions["onDragOver"]` | Callback for when the dragover event occurs. | | `onDrop` | - | `DropzoneOptions["onDrop"]` | Callback for when the drop event occurs. Note that this callback is invoked after the `getFilesFromEvent` callback is done. | | `onDropAccepted` | - | `DropzoneOptions["onDropAccepted"]` | Callback for when the drop event occurs. Note that if no files are accepted, this callback is not invoked. | | `onDropRejected` | - | `DropzoneOptions["onDropRejected"]` | Callback for when the drop event occurs. Note that if no files are rejected, this callback is not invoked. | | `onError` | - | `DropzoneOptions["onError"]` | Callback for when there's some error from any of the promises. | | `onFileDialogCancel` | - | `DropzoneOptions["onFileDialogCancel"]` | Callback for when closing the file dialog with no selection. | | `onFileDialogOpen` | - | `DropzoneOptions["onFileDialogOpen"]` | Callback for when opening the file dialog. | | `openRef` | - | `RefObject<() => void>` | Ref to a open function. | | `overlayProps` | - | `DropzoneOverlayProps` | Props for dropzone overlay element. | | `preventDropOnDocument` | `true` | `boolean` | If false, allow dropped items to take over the current browser window. | | `readOnly` | `false` | `boolean` | If `true`, the field will be readonly. | | `required` | `false` | `boolean` | If `true`, the field will be required. | | `useFsAccessApi` | `false` | `boolean` | If true, use the [File System API](https://developer.mozilla.org/en-US/docs/Web/API/File_System_API) to read files. | | `validator` | - | `DropzoneOptions["validator"]` | Custom validation function. It must return null if there's no errors. | ### Dropzone.Description | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ### Dropzone.Icon | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ### Dropzone.Title | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ## Accessibility Currently, this section is being updated due to the migration of v2.