diff --git a/src/index.js b/src/index.js index 3d1f3166..9d8ee83e 100755 --- a/src/index.js +++ b/src/index.js @@ -657,6 +657,7 @@ export function useDropzone(options = {}) { accept, minSize, maxSize, + maxFiles, getFilesFromEvent, onDrop, onDropAccepted, diff --git a/src/index.spec.js b/src/index.spec.js index 79e44cde..bff9bc74 100644 --- a/src/index.spec.js +++ b/src/index.spec.js @@ -2137,6 +2137,36 @@ describe('useDropzone() hook', () => { ], expect.anything()) }) + it('rejects all files if {multiple} is true and maxFiles has been updated so that it is less than files', async () => { + const onDropSpy = jest.fn() + const onDropRejectedSpy = jest.fn() + const ui = (maxFiles) => ( + + {({ getRootProps, getInputProps }) => ( +
+ +
+ )} +
+ ) + const { container, rerender } = render(ui(3)) + const dropzone = container.querySelector('div') + + fireDrop(dropzone, createDtWithFiles(images)) + await flushPromises(rerender, ui(3)) + expect(onDropRejectedSpy).not.toHaveBeenCalled() + expect(onDropSpy).toHaveBeenCalledWith(images, [], expect.anything()) + + rerender(ui(1)); + + fireDrop(dropzone, createDtWithFiles(images)) + await flushPromises(rerender, ui(1)) + expect(onDropRejectedSpy).toHaveBeenCalledWith( + expect.arrayContaining(images.map((image) => expect.objectContaining({ errors: expect.any(Array), file: image }))), + expect.anything() + ) + }) + it('accepts multiple files if {multiple} is true and {accept} criteria is met', async () => { const onDropSpy = jest.fn() const onDropRejectedSpy = jest.fn()