Skip to content

Commit 2633195

Browse files
authored
FileUploader: no error should be thrown on drag to custom dropZone specified as a string
1 parent 5c59b4f commit 2633195

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

packages/devextreme/js/__internal/ui/file_uploader.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,20 +1747,16 @@ class FileUploader extends Editor<FileUploaderProperties> {
17471747

17481748
_getDropZoneElement(isCustomTarget: boolean, e: DxEvent): Element | undefined {
17491749
if (!e.currentTarget) {
1750-
return;
1750+
return undefined;
17511751
}
17521752

17531753
const { dropZone } = this.option();
17541754

1755-
// @ts-expect-error dropZone option public type: it can be an array of Elements or NodeList
1756-
const targetList = isCustomTarget ? Array.from(dropZone) : [this._$inputWrapper];
1757-
1758-
const targetListElements = targetList.map(
1759-
(element: dxElementWrapper | string) => $(element).get(0),
1760-
);
1755+
const targetList = isCustomTarget ? $(dropZone).toArray() : [this._$inputWrapper];
1756+
const targetListElements = targetList.map((element) => $(element).get(0));
1757+
const currentTargetIndex = targetListElements.indexOf(e.currentTarget);
17611758

1762-
// eslint-disable-next-line consistent-return
1763-
return targetListElements[targetListElements.indexOf(e.currentTarget)];
1759+
return targetListElements[currentTargetIndex];
17641760
}
17651761

17661762
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type, consistent-return

packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/fileUploader.tests.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3901,6 +3901,25 @@ QUnit.module('Drag and drop', moduleConfig, () => {
39013901
assert.notOk(onDropZoneLeaveSpy.called);
39023902
});
39033903

3904+
QUnit.test('dropZoneEnter should not cause an error if custom dropZone is specified as string', function(assert) {
3905+
const customDropZone = $('<div>').addClass('drop').appendTo('#qunit-fixture');
3906+
const onDropZoneEnterSpy = sinon.spy();
3907+
3908+
$('#fileuploader').dxFileUploader({
3909+
uploadMode: 'useButtons',
3910+
dropZone: '.drop',
3911+
onDropZoneEnter: onDropZoneEnterSpy
3912+
});
3913+
3914+
try {
3915+
triggerDragEvent(customDropZone, 'dragenter');
3916+
3917+
assert.ok(true, 'No error is thrown');
3918+
} catch(error) {
3919+
assert.ok(false, `Error is thrown: ${error}`);
3920+
}
3921+
});
3922+
39043923
QUnit.test('onValueChanged event should not fire if dragged item is not file', function(assert) {
39053924
const onValueChangedSpy = sinon.spy();
39063925

0 commit comments

Comments
 (0)