Skip to content

Commit

Permalink
block uploading multiple files using dropzone
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBechirMejri authored and bassem97 committed Sep 4, 2023
1 parent 187a869 commit 9fc82a4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/UpupUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export const UpupUploader: FC<UpupUploaderProps & RefAttributes<any>> =
<DropZone
setFiles={setFiles}
setIsDragging={setIsDragging}
multiple={multiple}
/>
)}
</AnimatePresence>
Expand Down
9 changes: 8 additions & 1 deletion src/components/UpupUploader/DropZone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { TbUpload } from 'react-icons/tb'
export default function DropZone({
setFiles,
setIsDragging,
multiple,
}: {
setFiles: React.Dispatch<React.SetStateAction<File[]>>
setIsDragging: React.Dispatch<React.SetStateAction<boolean>>
multiple?: boolean
}) {
return (
<motion.div
Expand All @@ -32,7 +34,12 @@ export default function DropZone({
className="w-full h-full absolute top-0 opacity-0"
multiple
onChange={e => {
setFiles(prev => [...prev, ...Array.from(e.target.files!)])
setFiles(prev =>
multiple
? [...prev, ...Array.from(e.target.files!)]
: // only one file
[e.target.files![0]],
)
setIsDragging(false)
}}
onDrop={e => {
Expand Down

0 comments on commit 9fc82a4

Please sign in to comment.