react-dropzone 4.2.10 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/index.js +84 -62
- package/dist/es/utils/index.js +2 -0
- package/dist/index.js +2 -2
- package/examples/FileDialog/Readme.md +18 -0
- package/package.json +4 -4
- package/src/__snapshots__/index.spec.js.snap +7 -7
- package/src/index.js +84 -56
- package/src/index.spec.js +86 -85
- package/src/utils/index.js +2 -0
- package/styleguide.config.js +1 -1
- package/examples/File Dialog/Readme.md +0 -16
package/src/index.spec.js
CHANGED
|
@@ -361,21 +361,21 @@ describe('Dropzone', () => {
|
|
|
361
361
|
dragOverSpy.restore()
|
|
362
362
|
})
|
|
363
363
|
|
|
364
|
-
it('should set proper dragActive state on dragEnter', () => {
|
|
364
|
+
it('should set proper dragActive state on dragEnter', async () => {
|
|
365
365
|
const dropzone = mount(<Dropzone>{props => <DummyChildComponent {...props} />}</Dropzone>)
|
|
366
366
|
const child = dropzone.find(DummyChildComponent)
|
|
367
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
367
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
368
368
|
expect(child).toHaveProp('isDragActive', true)
|
|
369
369
|
expect(child).toHaveProp('isDragAccept', true)
|
|
370
370
|
expect(child).toHaveProp('isDragReject', false)
|
|
371
371
|
})
|
|
372
372
|
|
|
373
|
-
it('should set proper dragReject state on dragEnter', () => {
|
|
373
|
+
it('should set proper dragReject state on dragEnter', async () => {
|
|
374
374
|
const dropzone = mount(
|
|
375
375
|
<Dropzone accept="image/*">{props => <DummyChildComponent {...props} />}</Dropzone>
|
|
376
376
|
)
|
|
377
377
|
const child = dropzone.find(DummyChildComponent)
|
|
378
|
-
dropzone.simulate('dragEnter', {
|
|
378
|
+
await dropzone.simulate('dragEnter', {
|
|
379
379
|
dataTransfer: { files: files.concat(images) }
|
|
380
380
|
})
|
|
381
381
|
expect(child).toHaveProp('isDragActive', true)
|
|
@@ -383,64 +383,64 @@ describe('Dropzone', () => {
|
|
|
383
383
|
expect(child).toHaveProp('isDragReject', true)
|
|
384
384
|
})
|
|
385
385
|
|
|
386
|
-
it('should set proper dragAccept state if multiple is false', () => {
|
|
386
|
+
it('should set proper dragAccept state if multiple is false', async () => {
|
|
387
387
|
const dropzone = mount(
|
|
388
388
|
<Dropzone accept="image/*" multiple={false}>
|
|
389
389
|
{props => <DummyChildComponent {...props} />}
|
|
390
390
|
</Dropzone>
|
|
391
391
|
)
|
|
392
392
|
const child = dropzone.find(DummyChildComponent)
|
|
393
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
393
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
394
394
|
expect(child).toHaveProp('isDragActive', true)
|
|
395
395
|
expect(child).toHaveProp('isDragAccept', false)
|
|
396
396
|
expect(child).toHaveProp('isDragReject', true)
|
|
397
397
|
})
|
|
398
398
|
|
|
399
|
-
it('should set proper dragAccept state if multiple is false', () => {
|
|
399
|
+
it('should set proper dragAccept state if multiple is false', async () => {
|
|
400
400
|
const dropzone = mount(
|
|
401
401
|
<Dropzone accept="image/*" multiple={false}>
|
|
402
402
|
{props => <DummyChildComponent {...props} />}
|
|
403
403
|
</Dropzone>
|
|
404
404
|
)
|
|
405
405
|
const child = dropzone.find(DummyChildComponent)
|
|
406
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
406
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
407
407
|
expect(child).toHaveProp('isDragActive', true)
|
|
408
408
|
expect(child).toHaveProp('isDragAccept', true)
|
|
409
409
|
expect(child).toHaveProp('isDragReject', true)
|
|
410
410
|
})
|
|
411
411
|
|
|
412
|
-
it('should set activeClassName properly', () => {
|
|
412
|
+
it('should set activeClassName properly', async () => {
|
|
413
413
|
const dropzone = mount(
|
|
414
414
|
<Dropzone accept="image/*" activeClassName="👏" multiple={false}>
|
|
415
415
|
{props => <DummyChildComponent {...props} />}
|
|
416
416
|
</Dropzone>
|
|
417
417
|
)
|
|
418
418
|
const child = dropzone.find(DummyChildComponent)
|
|
419
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
419
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
420
420
|
expect(child).toHaveProp('isDragActive', true)
|
|
421
421
|
expect(dropzone.hasClass('👏')).toBe(true)
|
|
422
422
|
})
|
|
423
423
|
|
|
424
|
-
it('should set rejectClassName properly', () => {
|
|
424
|
+
it('should set rejectClassName properly', async () => {
|
|
425
425
|
const dropzone = mount(
|
|
426
426
|
<Dropzone accept="image/*" rejectClassName="👎" multiple={false}>
|
|
427
427
|
{props => <DummyChildComponent {...props} />}
|
|
428
428
|
</Dropzone>
|
|
429
429
|
)
|
|
430
430
|
const child = dropzone.find(DummyChildComponent)
|
|
431
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
431
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
432
432
|
expect(child).toHaveProp('isDragReject', true)
|
|
433
433
|
expect(dropzone.hasClass('👎')).toBe(true)
|
|
434
434
|
})
|
|
435
435
|
|
|
436
|
-
it('should set acceptClassName properly', () => {
|
|
436
|
+
it('should set acceptClassName properly', async () => {
|
|
437
437
|
const dropzone = mount(
|
|
438
438
|
<Dropzone accept="image/*" acceptClassName="👍" className="foo" multiple={false}>
|
|
439
439
|
{props => <DummyChildComponent {...props} />}
|
|
440
440
|
</Dropzone>
|
|
441
441
|
)
|
|
442
442
|
const child = dropzone.find(DummyChildComponent)
|
|
443
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
443
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
444
444
|
expect(child).toHaveProp('isDragAccept', true)
|
|
445
445
|
expect(dropzone.hasClass('👍')).toBe(true)
|
|
446
446
|
})
|
|
@@ -454,16 +454,16 @@ describe('Dropzone', () => {
|
|
|
454
454
|
expect(dropzone.hasClass('🤐')).toBe(true)
|
|
455
455
|
})
|
|
456
456
|
|
|
457
|
-
it('should keep dragging active when leaving from arbitrary node', () => {
|
|
457
|
+
it('should keep dragging active when leaving from arbitrary node', async () => {
|
|
458
458
|
const arbitraryOverlay = mount(<div />)
|
|
459
459
|
const dropzone = mount(<Dropzone>{props => <DummyChildComponent {...props} />}</Dropzone>)
|
|
460
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
460
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
461
461
|
dropzone.simulate('dragLeave', { target: arbitraryOverlay })
|
|
462
462
|
expect(dropzone.state('isDragActive')).toBe(true)
|
|
463
463
|
expect(dropzone.state('draggedFiles').length > 0).toBe(true)
|
|
464
464
|
})
|
|
465
465
|
|
|
466
|
-
it('should apply acceptStyle if multiple is false and single file', () => {
|
|
466
|
+
it('should apply acceptStyle if multiple is false and single file', async () => {
|
|
467
467
|
const dropzone = mount(
|
|
468
468
|
<Dropzone
|
|
469
469
|
accept="image/*"
|
|
@@ -474,12 +474,12 @@ describe('Dropzone', () => {
|
|
|
474
474
|
{props => <DummyChildComponent {...props} />}
|
|
475
475
|
</Dropzone>
|
|
476
476
|
)
|
|
477
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files: [images[0]] } })
|
|
477
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files: [images[0]] } })
|
|
478
478
|
const mainDiv = dropzone.find('div').at(0)
|
|
479
|
-
expect(mainDiv).toHaveProp('style', acceptStyle)
|
|
479
|
+
expect(mainDiv).toHaveProp('style', { position: 'relative', ...acceptStyle })
|
|
480
480
|
})
|
|
481
481
|
|
|
482
|
-
it('should apply rejectStyle if multiple is false and single bad file type', () => {
|
|
482
|
+
it('should apply rejectStyle if multiple is false and single bad file type', async () => {
|
|
483
483
|
const dropzone = mount(
|
|
484
484
|
<Dropzone
|
|
485
485
|
accept="image/*"
|
|
@@ -490,12 +490,12 @@ describe('Dropzone', () => {
|
|
|
490
490
|
{props => <DummyChildComponent {...props} />}
|
|
491
491
|
</Dropzone>
|
|
492
492
|
)
|
|
493
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files: [files[0]] } })
|
|
493
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files: [files[0]] } })
|
|
494
494
|
const mainDiv = dropzone.find('div').at(0)
|
|
495
|
-
expect(mainDiv).toHaveProp('style', rejectStyle)
|
|
495
|
+
expect(mainDiv).toHaveProp('style', { position: 'relative', ...rejectStyle })
|
|
496
496
|
})
|
|
497
497
|
|
|
498
|
-
it('should apply acceptStyle + rejectStyle if multiple is false and multiple good file types', () => {
|
|
498
|
+
it('should apply acceptStyle + rejectStyle if multiple is false and multiple good file types', async () => {
|
|
499
499
|
const dropzone = mount(
|
|
500
500
|
<Dropzone
|
|
501
501
|
accept="image/*"
|
|
@@ -506,21 +506,22 @@ describe('Dropzone', () => {
|
|
|
506
506
|
{props => <DummyChildComponent {...props} />}
|
|
507
507
|
</Dropzone>
|
|
508
508
|
)
|
|
509
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
509
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
510
510
|
const mainDiv = dropzone.find('div').at(0)
|
|
511
511
|
const expectedStyle = {
|
|
512
|
+
position: 'relative',
|
|
512
513
|
...acceptStyle,
|
|
513
514
|
...rejectStyle
|
|
514
515
|
}
|
|
515
516
|
expect(mainDiv).toHaveProp('style', expectedStyle)
|
|
516
517
|
})
|
|
517
518
|
|
|
518
|
-
it('should set proper dragActive state if accept prop changes mid-drag', () => {
|
|
519
|
+
it('should set proper dragActive state if accept prop changes mid-drag', async () => {
|
|
519
520
|
const dropzone = mount(
|
|
520
521
|
<Dropzone accept="image/*">{props => <DummyChildComponent {...props} />}</Dropzone>
|
|
521
522
|
)
|
|
522
523
|
const child = dropzone.find(DummyChildComponent)
|
|
523
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
524
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
524
525
|
expect(child).toHaveProp('isDragActive', true)
|
|
525
526
|
expect(child).toHaveProp('isDragAccept', true)
|
|
526
527
|
expect(child).toHaveProp('isDragReject', false)
|
|
@@ -531,7 +532,7 @@ describe('Dropzone', () => {
|
|
|
531
532
|
expect(child).toHaveProp('isDragReject', true)
|
|
532
533
|
})
|
|
533
534
|
|
|
534
|
-
it('should expose state to children', () => {
|
|
535
|
+
it('should expose state to children', async () => {
|
|
535
536
|
const dropzone = mount(
|
|
536
537
|
<Dropzone accept="image/*">
|
|
537
538
|
{({ isDragActive, isDragAccept, isDragReject }) => {
|
|
@@ -546,13 +547,13 @@ describe('Dropzone', () => {
|
|
|
546
547
|
</Dropzone>
|
|
547
548
|
)
|
|
548
549
|
expect(dropzone.text()).toEqual('Empty')
|
|
549
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
550
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files: images } })
|
|
550
551
|
expect(dropzone.text()).toEqual('Active and Accept')
|
|
551
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
552
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
552
553
|
expect(dropzone.text()).toEqual('Active but Reject')
|
|
553
554
|
})
|
|
554
555
|
|
|
555
|
-
it('should reset the dragAccept/dragReject state when leaving after a child goes away', () => {
|
|
556
|
+
it('should reset the dragAccept/dragReject state when leaving after a child goes away', async () => {
|
|
556
557
|
const DragActiveComponent = () => <p>Accept</p>
|
|
557
558
|
const ChildComponent = () => <p>Child component content</p>
|
|
558
559
|
const dropzone = mount(
|
|
@@ -570,9 +571,9 @@ describe('Dropzone', () => {
|
|
|
570
571
|
)
|
|
571
572
|
const child = dropzone.find(ChildComponent)
|
|
572
573
|
child.simulate('dragEnter', { dataTransfer: { files } })
|
|
573
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
574
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
574
575
|
// make sure we handle any duplicate dragEnter events that the browser may send us
|
|
575
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
576
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
576
577
|
const dragActiveChild = dropzone.find(DragActiveComponent)
|
|
577
578
|
expect(dragActiveChild).toBePresent()
|
|
578
579
|
expect(dragActiveChild).toHaveProp('isDragAccept', true)
|
|
@@ -602,7 +603,7 @@ describe('Dropzone', () => {
|
|
|
602
603
|
dropRejectedSpy.reset()
|
|
603
604
|
})
|
|
604
605
|
|
|
605
|
-
it('should reset the dragActive/dragReject state', () => {
|
|
606
|
+
it('should reset the dragActive/dragReject state', async () => {
|
|
606
607
|
const dropzone = mount(
|
|
607
608
|
<Dropzone
|
|
608
609
|
onDrop={dropSpy}
|
|
@@ -613,7 +614,7 @@ describe('Dropzone', () => {
|
|
|
613
614
|
</Dropzone>
|
|
614
615
|
)
|
|
615
616
|
const child = dropzone.find(DummyChildComponent)
|
|
616
|
-
dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
617
|
+
await dropzone.simulate('dragEnter', { dataTransfer: { files } })
|
|
617
618
|
expect(child).toHaveProp('isDragActive', true)
|
|
618
619
|
expect(child).toHaveProp('isDragReject', false)
|
|
619
620
|
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
@@ -621,47 +622,47 @@ describe('Dropzone', () => {
|
|
|
621
622
|
expect(child).toHaveProp('isDragReject', false)
|
|
622
623
|
})
|
|
623
624
|
|
|
624
|
-
it('should add valid files to rejected files on a multple drop when multiple false', () => {
|
|
625
|
+
it('should add valid files to rejected files on a multple drop when multiple false', async () => {
|
|
625
626
|
const dropzone = mount(<Dropzone accept="image/*" onDrop={dropSpy} multiple={false} />)
|
|
626
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
627
|
+
await dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
627
628
|
const rejected = dropSpy.firstCall.args[0]
|
|
628
629
|
expect(rejected.length).toEqual(1)
|
|
629
630
|
})
|
|
630
631
|
|
|
631
|
-
it('should add invalid files to rejected when multiple is false', () => {
|
|
632
|
+
it('should add invalid files to rejected when multiple is false', async () => {
|
|
632
633
|
const dropzone = mount(<Dropzone accept="image/*" onDrop={dropSpy} multiple={false} />)
|
|
633
|
-
dropzone.simulate('drop', {
|
|
634
|
+
await dropzone.simulate('drop', {
|
|
634
635
|
dataTransfer: { files: images.concat(files) }
|
|
635
636
|
})
|
|
636
637
|
const rejected = dropSpy.firstCall.args[1]
|
|
637
638
|
expect(rejected.length).toEqual(2)
|
|
638
639
|
})
|
|
639
640
|
|
|
640
|
-
it('should allow single files to be dropped if multiple is false', () => {
|
|
641
|
+
it('should allow single files to be dropped if multiple is false', async () => {
|
|
641
642
|
const dropzone = mount(<Dropzone accept="image/*" onDrop={dropSpy} multiple={false} />)
|
|
642
643
|
|
|
643
|
-
dropzone.simulate('drop', { dataTransfer: { files: [images[0]] } })
|
|
644
|
+
await dropzone.simulate('drop', { dataTransfer: { files: [images[0]] } })
|
|
644
645
|
const [accepted, rejected] = dropSpy.firstCall.args
|
|
645
646
|
expect(accepted.length).toEqual(1)
|
|
646
647
|
expect(rejected.length).toEqual(0)
|
|
647
648
|
})
|
|
648
649
|
|
|
649
|
-
it('should take all dropped files if multiple is true', () => {
|
|
650
|
+
it('should take all dropped files if multiple is true', async () => {
|
|
650
651
|
const dropzone = mount(<Dropzone onDrop={dropSpy} multiple />)
|
|
651
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
652
|
+
await dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
652
653
|
expect(dropSpy.firstCall.args[0]).toHaveLength(2)
|
|
653
654
|
expect(dropSpy.firstCall.args[0][0].name).toEqual(images[0].name)
|
|
654
655
|
expect(dropSpy.firstCall.args[0][1].name).toEqual(images[1].name)
|
|
655
656
|
})
|
|
656
657
|
|
|
657
|
-
it('should set this.isFileDialogActive to false', () => {
|
|
658
|
+
it('should set this.isFileDialogActive to false', async () => {
|
|
658
659
|
const dropzone = mount(<Dropzone />)
|
|
659
660
|
dropzone.instance().isFileDialogActive = true
|
|
660
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
661
|
+
await dropzone.simulate('drop', { dataTransfer: { files } })
|
|
661
662
|
expect(dropzone.instance().isFileDialogActive).toEqual(false)
|
|
662
663
|
})
|
|
663
664
|
|
|
664
|
-
it('should always call onDrop callback with accepted and rejected arguments', () => {
|
|
665
|
+
it('should always call onDrop callback with accepted and rejected arguments', async () => {
|
|
665
666
|
const dropzone = mount(
|
|
666
667
|
<Dropzone
|
|
667
668
|
onDrop={dropSpy}
|
|
@@ -670,20 +671,20 @@ describe('Dropzone', () => {
|
|
|
670
671
|
accept="image/*"
|
|
671
672
|
/>
|
|
672
673
|
)
|
|
673
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
674
|
+
await dropzone.simulate('drop', { dataTransfer: { files } })
|
|
674
675
|
expect(dropSpy.callCount).toEqual(1)
|
|
675
676
|
expect(dropSpy.firstCall.args[0]).toEqual([], [...files])
|
|
676
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
677
|
+
await dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
677
678
|
expect(dropSpy.callCount).toEqual(2)
|
|
678
679
|
expect(dropSpy.lastCall.args[0]).toEqual([...images], [])
|
|
679
|
-
dropzone.simulate('drop', {
|
|
680
|
+
await dropzone.simulate('drop', {
|
|
680
681
|
dataTransfer: { files: files.concat(images) }
|
|
681
682
|
})
|
|
682
683
|
expect(dropSpy.callCount).toEqual(3)
|
|
683
684
|
expect(dropSpy.lastCall.args[0]).toEqual([...images], [...files])
|
|
684
685
|
})
|
|
685
686
|
|
|
686
|
-
it('should call onDropAccepted callback if some files were accepted', () => {
|
|
687
|
+
it('should call onDropAccepted callback if some files were accepted', async () => {
|
|
687
688
|
const dropzone = mount(
|
|
688
689
|
<Dropzone
|
|
689
690
|
onDrop={dropSpy}
|
|
@@ -692,19 +693,19 @@ describe('Dropzone', () => {
|
|
|
692
693
|
accept="image/*"
|
|
693
694
|
/>
|
|
694
695
|
)
|
|
695
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
696
|
+
await dropzone.simulate('drop', { dataTransfer: { files } })
|
|
696
697
|
expect(dropAcceptedSpy.callCount).toEqual(0)
|
|
697
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
698
|
+
await dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
698
699
|
expect(dropAcceptedSpy.callCount).toEqual(1)
|
|
699
700
|
expect(dropAcceptedSpy.lastCall.args[0]).toEqual([...images])
|
|
700
|
-
dropzone.simulate('drop', {
|
|
701
|
+
await dropzone.simulate('drop', {
|
|
701
702
|
dataTransfer: { files: files.concat(images) }
|
|
702
703
|
})
|
|
703
704
|
expect(dropAcceptedSpy.callCount).toEqual(2)
|
|
704
705
|
expect(dropAcceptedSpy.lastCall.args[0]).toEqual([...images])
|
|
705
706
|
})
|
|
706
707
|
|
|
707
|
-
it('should call onDropRejected callback if some files were rejected', () => {
|
|
708
|
+
it('should call onDropRejected callback if some files were rejected', async () => {
|
|
708
709
|
const dropzone = mount(
|
|
709
710
|
<Dropzone
|
|
710
711
|
onDrop={dropSpy}
|
|
@@ -713,19 +714,19 @@ describe('Dropzone', () => {
|
|
|
713
714
|
accept="image/*"
|
|
714
715
|
/>
|
|
715
716
|
)
|
|
716
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
717
|
+
await dropzone.simulate('drop', { dataTransfer: { files } })
|
|
717
718
|
expect(dropRejectedSpy.callCount).toEqual(1)
|
|
718
719
|
expect(dropRejectedSpy.lastCall.args[0]).toEqual([...files])
|
|
719
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
720
|
+
await dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
720
721
|
expect(dropRejectedSpy.callCount).toEqual(1)
|
|
721
|
-
dropzone.simulate('drop', {
|
|
722
|
+
await dropzone.simulate('drop', {
|
|
722
723
|
dataTransfer: { files: files.concat(images) }
|
|
723
724
|
})
|
|
724
725
|
expect(dropRejectedSpy.callCount).toEqual(2)
|
|
725
726
|
expect(dropRejectedSpy.lastCall.args[0]).toEqual([...files])
|
|
726
727
|
})
|
|
727
728
|
|
|
728
|
-
it('applies the accept prop to the dropped files', () => {
|
|
729
|
+
it('applies the accept prop to the dropped files', async () => {
|
|
729
730
|
const dropzone = mount(
|
|
730
731
|
<Dropzone
|
|
731
732
|
onDrop={dropSpy}
|
|
@@ -734,7 +735,7 @@ describe('Dropzone', () => {
|
|
|
734
735
|
accept="image/*"
|
|
735
736
|
/>
|
|
736
737
|
)
|
|
737
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
738
|
+
await dropzone.simulate('drop', { dataTransfer: { files } })
|
|
738
739
|
expect(dropSpy.callCount).toEqual(1)
|
|
739
740
|
expect(dropSpy.firstCall.args[0]).toHaveLength(0)
|
|
740
741
|
expect(dropSpy.firstCall.args[1]).toHaveLength(1)
|
|
@@ -743,7 +744,7 @@ describe('Dropzone', () => {
|
|
|
743
744
|
expect(dropRejectedSpy.firstCall.args[0]).toHaveLength(1)
|
|
744
745
|
})
|
|
745
746
|
|
|
746
|
-
it('applies the accept prop to the dropped images', () => {
|
|
747
|
+
it('applies the accept prop to the dropped images', async () => {
|
|
747
748
|
const dropzone = mount(
|
|
748
749
|
<Dropzone
|
|
749
750
|
onDrop={dropSpy}
|
|
@@ -753,7 +754,7 @@ describe('Dropzone', () => {
|
|
|
753
754
|
/>
|
|
754
755
|
)
|
|
755
756
|
|
|
756
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
757
|
+
await dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
757
758
|
expect(dropSpy.callCount).toEqual(1)
|
|
758
759
|
expect(dropSpy.firstCall.args[0]).toHaveLength(2)
|
|
759
760
|
expect(dropSpy.firstCall.args[1]).toHaveLength(0)
|
|
@@ -762,7 +763,7 @@ describe('Dropzone', () => {
|
|
|
762
763
|
expect(dropRejectedSpy.callCount).toEqual(0)
|
|
763
764
|
})
|
|
764
765
|
|
|
765
|
-
it('accepts a dropped image when Firefox provides a bogus file type', () => {
|
|
766
|
+
it('accepts a dropped image when Firefox provides a bogus file type', async () => {
|
|
766
767
|
const dropzone = mount(
|
|
767
768
|
<Dropzone
|
|
768
769
|
onDrop={dropSpy}
|
|
@@ -779,7 +780,7 @@ describe('Dropzone', () => {
|
|
|
779
780
|
}
|
|
780
781
|
]
|
|
781
782
|
|
|
782
|
-
dropzone.simulate('drop', { dataTransfer: { files: bogusImages } })
|
|
783
|
+
await dropzone.simulate('drop', { dataTransfer: { files: bogusImages } })
|
|
783
784
|
expect(dropSpy.callCount).toEqual(1)
|
|
784
785
|
expect(dropSpy.firstCall.args[0]).toHaveLength(1)
|
|
785
786
|
expect(dropSpy.firstCall.args[1]).toHaveLength(0)
|
|
@@ -788,7 +789,7 @@ describe('Dropzone', () => {
|
|
|
788
789
|
expect(dropRejectedSpy.callCount).toEqual(0)
|
|
789
790
|
})
|
|
790
791
|
|
|
791
|
-
it('accepts all dropped files and images when no accept prop is specified', () => {
|
|
792
|
+
it('accepts all dropped files and images when no accept prop is specified', async () => {
|
|
792
793
|
const dropzone = mount(
|
|
793
794
|
<Dropzone
|
|
794
795
|
onDrop={dropSpy}
|
|
@@ -796,7 +797,7 @@ describe('Dropzone', () => {
|
|
|
796
797
|
onDropRejected={dropRejectedSpy}
|
|
797
798
|
/>
|
|
798
799
|
)
|
|
799
|
-
dropzone.simulate('drop', {
|
|
800
|
+
await dropzone.simulate('drop', {
|
|
800
801
|
dataTransfer: { files: files.concat(images) }
|
|
801
802
|
})
|
|
802
803
|
expect(dropSpy.callCount).toEqual(1)
|
|
@@ -807,7 +808,7 @@ describe('Dropzone', () => {
|
|
|
807
808
|
expect(dropRejectedSpy.callCount).toEqual(0)
|
|
808
809
|
})
|
|
809
810
|
|
|
810
|
-
it('applies the maxSize prop to the dropped files', () => {
|
|
811
|
+
it('applies the maxSize prop to the dropped files', async () => {
|
|
811
812
|
const dropzone = mount(
|
|
812
813
|
<Dropzone
|
|
813
814
|
onDrop={dropSpy}
|
|
@@ -817,7 +818,7 @@ describe('Dropzone', () => {
|
|
|
817
818
|
/>
|
|
818
819
|
)
|
|
819
820
|
|
|
820
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
821
|
+
await dropzone.simulate('drop', { dataTransfer: { files } })
|
|
821
822
|
expect(dropSpy.callCount).toEqual(1)
|
|
822
823
|
expect(dropSpy.firstCall.args[0]).toHaveLength(1)
|
|
823
824
|
expect(dropSpy.firstCall.args[1]).toHaveLength(0)
|
|
@@ -826,7 +827,7 @@ describe('Dropzone', () => {
|
|
|
826
827
|
expect(dropRejectedSpy.callCount).toEqual(0)
|
|
827
828
|
})
|
|
828
829
|
|
|
829
|
-
it('applies the maxSize prop to the dropped images', () => {
|
|
830
|
+
it('applies the maxSize prop to the dropped images', async () => {
|
|
830
831
|
const dropzone = mount(
|
|
831
832
|
<Dropzone
|
|
832
833
|
onDrop={dropSpy}
|
|
@@ -835,7 +836,7 @@ describe('Dropzone', () => {
|
|
|
835
836
|
maxSize={1111}
|
|
836
837
|
/>
|
|
837
838
|
)
|
|
838
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
839
|
+
await dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
839
840
|
expect(dropSpy.callCount).toEqual(1)
|
|
840
841
|
expect(dropSpy.firstCall.args[0]).toHaveLength(0)
|
|
841
842
|
expect(dropSpy.firstCall.args[1]).toHaveLength(2)
|
|
@@ -844,7 +845,7 @@ describe('Dropzone', () => {
|
|
|
844
845
|
expect(dropRejectedSpy.firstCall.args[0]).toHaveLength(2)
|
|
845
846
|
})
|
|
846
847
|
|
|
847
|
-
it('applies the minSize prop to the dropped files', () => {
|
|
848
|
+
it('applies the minSize prop to the dropped files', async () => {
|
|
848
849
|
const dropzone = mount(
|
|
849
850
|
<Dropzone
|
|
850
851
|
onDrop={dropSpy}
|
|
@@ -853,7 +854,7 @@ describe('Dropzone', () => {
|
|
|
853
854
|
minSize={1112}
|
|
854
855
|
/>
|
|
855
856
|
)
|
|
856
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
857
|
+
await dropzone.simulate('drop', { dataTransfer: { files } })
|
|
857
858
|
expect(dropSpy.callCount).toEqual(1)
|
|
858
859
|
expect(dropSpy.firstCall.args[0]).toHaveLength(0)
|
|
859
860
|
expect(dropSpy.firstCall.args[1]).toHaveLength(1)
|
|
@@ -862,7 +863,7 @@ describe('Dropzone', () => {
|
|
|
862
863
|
expect(dropRejectedSpy.firstCall.args[0]).toHaveLength(1)
|
|
863
864
|
})
|
|
864
865
|
|
|
865
|
-
it('applies the minSize prop to the dropped images', () => {
|
|
866
|
+
it('applies the minSize prop to the dropped images', async () => {
|
|
866
867
|
const dropzone = mount(
|
|
867
868
|
<Dropzone
|
|
868
869
|
onDrop={dropSpy}
|
|
@@ -871,7 +872,7 @@ describe('Dropzone', () => {
|
|
|
871
872
|
minSize={1112}
|
|
872
873
|
/>
|
|
873
874
|
)
|
|
874
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
875
|
+
await dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
875
876
|
expect(dropSpy.callCount).toEqual(1)
|
|
876
877
|
expect(dropSpy.firstCall.args[0]).toHaveLength(2)
|
|
877
878
|
expect(dropSpy.firstCall.args[1]).toHaveLength(0)
|
|
@@ -880,7 +881,7 @@ describe('Dropzone', () => {
|
|
|
880
881
|
expect(dropRejectedSpy.callCount).toEqual(0)
|
|
881
882
|
})
|
|
882
883
|
|
|
883
|
-
it('accepts all dropped files and images when no size prop is specified', () => {
|
|
884
|
+
it('accepts all dropped files and images when no size prop is specified', async () => {
|
|
884
885
|
const dropzone = mount(
|
|
885
886
|
<Dropzone
|
|
886
887
|
onDrop={dropSpy}
|
|
@@ -888,7 +889,7 @@ describe('Dropzone', () => {
|
|
|
888
889
|
onDropRejected={dropRejectedSpy}
|
|
889
890
|
/>
|
|
890
891
|
)
|
|
891
|
-
dropzone.simulate('drop', {
|
|
892
|
+
await dropzone.simulate('drop', {
|
|
892
893
|
dataTransfer: { files: files.concat(images) }
|
|
893
894
|
})
|
|
894
895
|
expect(dropSpy.callCount).toEqual(1)
|
|
@@ -901,36 +902,36 @@ describe('Dropzone', () => {
|
|
|
901
902
|
})
|
|
902
903
|
|
|
903
904
|
describe('preview', () => {
|
|
904
|
-
it('should generate previews for non-images', () => {
|
|
905
|
+
it('should generate previews for non-images', async () => {
|
|
905
906
|
const dropSpy = spy()
|
|
906
907
|
const dropzone = mount(<Dropzone onDrop={dropSpy} />)
|
|
907
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
908
|
+
await dropzone.simulate('drop', { dataTransfer: { files } })
|
|
908
909
|
expect(Object.keys(dropSpy.firstCall.args[0][0])).toContain('preview')
|
|
909
910
|
expect(dropSpy.firstCall.args[0][0].preview).toContain('data://file1.pdf')
|
|
910
911
|
})
|
|
911
912
|
|
|
912
|
-
it('should generate previews for images', () => {
|
|
913
|
+
it('should generate previews for images', async () => {
|
|
913
914
|
const dropSpy = spy()
|
|
914
915
|
const dropzone = mount(<Dropzone onDrop={dropSpy} />)
|
|
915
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
916
|
+
await dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
916
917
|
expect(Object.keys(dropSpy.firstCall.args[0][0])).toContain('preview')
|
|
917
918
|
expect(dropSpy.firstCall.args[0][0].preview).toContain('data://cats.gif')
|
|
918
919
|
})
|
|
919
920
|
|
|
920
|
-
it('should not throw error when preview cannot be created', () => {
|
|
921
|
+
it('should not throw error when preview cannot be created', async () => {
|
|
921
922
|
const dropSpy = spy()
|
|
922
923
|
const dropzone = mount(<Dropzone onDrop={dropSpy} />)
|
|
923
924
|
|
|
924
|
-
dropzone.simulate('drop', { dataTransfer: { files: ['bad_val'] } })
|
|
925
|
+
await dropzone.simulate('drop', { dataTransfer: { files: ['bad_val'] } })
|
|
925
926
|
|
|
926
927
|
expect(Object.keys(dropSpy.firstCall.args[1][0])).not.toContain('preview')
|
|
927
928
|
})
|
|
928
929
|
|
|
929
|
-
it('should not generate previews if disablePreview is true', () => {
|
|
930
|
+
it('should not generate previews if disablePreview is true', async () => {
|
|
930
931
|
const dropSpy = spy()
|
|
931
932
|
const dropzone = mount(<Dropzone disablePreview onDrop={dropSpy} />)
|
|
932
|
-
dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
933
|
-
dropzone.simulate('drop', { dataTransfer: { files } })
|
|
933
|
+
await dropzone.simulate('drop', { dataTransfer: { files: images } })
|
|
934
|
+
await dropzone.simulate('drop', { dataTransfer: { files } })
|
|
934
935
|
expect(dropSpy.callCount).toEqual(2)
|
|
935
936
|
expect(Object.keys(dropSpy.firstCall.args[0][0])).not.toContain('preview')
|
|
936
937
|
expect(Object.keys(dropSpy.lastCall.args[0][0])).not.toContain('preview')
|
|
@@ -1051,8 +1052,8 @@ describe('Dropzone', () => {
|
|
|
1051
1052
|
innerDropzone = outerDropzone.find(InnerDropzone)
|
|
1052
1053
|
})
|
|
1053
1054
|
|
|
1054
|
-
it('does dragEnter on both dropzones', () => {
|
|
1055
|
-
innerDropzone.simulate('dragEnter', {
|
|
1055
|
+
it('does dragEnter on both dropzones', async () => {
|
|
1056
|
+
await innerDropzone.simulate('dragEnter', {
|
|
1056
1057
|
dataTransfer: { files: images }
|
|
1057
1058
|
})
|
|
1058
1059
|
expect(innerDropzone).toHaveProp('isDragActive', true)
|
package/src/utils/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export function getDataTransferItems(event) {
|
|
|
9
9
|
let dataTransferItemsList = []
|
|
10
10
|
if (event.dataTransfer) {
|
|
11
11
|
const dt = event.dataTransfer
|
|
12
|
+
|
|
12
13
|
if (dt.files && dt.files.length) {
|
|
13
14
|
dataTransferItemsList = dt.files
|
|
14
15
|
} else if (dt.items && dt.items.length) {
|
|
@@ -19,6 +20,7 @@ export function getDataTransferItems(event) {
|
|
|
19
20
|
} else if (event.target && event.target.files) {
|
|
20
21
|
dataTransferItemsList = event.target.files
|
|
21
22
|
}
|
|
23
|
+
|
|
22
24
|
// Convert from DataTransferItemsList to the native Array
|
|
23
25
|
return Array.prototype.slice.call(dataTransferItemsList)
|
|
24
26
|
}
|
package/styleguide.config.js
CHANGED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
You can programmatically invoke default OS file prompt. In order to do that you'll have to set the ref on your `Dropzone` instance and call the instance `open` method.
|
|
2
|
-
|
|
3
|
-
```
|
|
4
|
-
let dropzoneRef;
|
|
5
|
-
|
|
6
|
-
<div>
|
|
7
|
-
<Dropzone ref={(node) => { dropzoneRef = node; }} onDrop={(accepted, rejected) => { alert(accepted) }}>
|
|
8
|
-
<p>Drop files here.</p>
|
|
9
|
-
</Dropzone>
|
|
10
|
-
<button type="button" onClick={() => { dropzoneRef.open() }}>
|
|
11
|
-
Open File Dialog
|
|
12
|
-
</button>
|
|
13
|
-
</div>
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
The completion handler for the `open` function is also the `onDrop` function.
|