Skip to content

Commit d06517e

Browse files
authored
Merge pull request #453 from UiPath/fix/file-picker/highlight-applied-when-dragging-links
fix(file-picker): dropzone should only highlight when dragging files
2 parents bb15b2c + fdedc41 commit d06517e

File tree

6 files changed

+46
-12
lines changed

6 files changed

+46
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# v15.1.4 (2024-02-02)
2+
* **file-picker** dropzone should only highlight when dragging files
3+
14
# v15.1.3 (2024-01-30)
25
* **grid** exclude emtpy array from filter value
36

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-components",
3-
"version": "15.1.3",
3+
"version": "15.1.4",
44
"author": {
55
"name": "UiPath Inc",
66
"url": "https://uipath.com"

projects/angular/directives/ui-file-drop-zone/src/ui-file-drop-zone.directive.spec.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,24 @@ describe('UiFileDropZoneDirective', () => {
7272
});
7373

7474
describe('dragging and dropping files', () => {
75-
it('should add class to drop zone when dragging over', () => {
75+
it('should not add class to drop zone when entering the drag zone', () => {
76+
spectator.dispatchMouseEvent(byTestId('custom-drop-zone'), 'dragenter', 0, 0, getDragEventWithDataTransfer('dragover'));
77+
spectator.detectChanges();
78+
79+
expect(spectator.query(byTestId('custom-drop-zone'))).not.toHaveClass('ui-file-drop-zone-highlight');
80+
});
81+
82+
it('should not add class to drop zone when entering the drag zone with data that does not include files', () => {
7683
spectator.dispatchMouseEvent(byTestId('custom-drop-zone'), 'dragenter');
84+
spectator.dispatchMouseEvent(byTestId('custom-drop-zone'), 'dragover', 0, 0, getDragEventWithDataTransfer('dragover', false));
7785
spectator.detectChanges();
7886

79-
expect(spectator.query(byTestId('custom-drop-zone'))).toHaveClass('ui-file-drop-zone-highlight');
87+
expect(spectator.query(byTestId('custom-drop-zone'))).not.toHaveClass('ui-file-drop-zone-highlight');
8088
});
8189

8290
it('should not remove highlight class when dragging over an element inside the dropzone', () => {
8391
spectator.dispatchMouseEvent(byTestId('custom-drop-zone'), 'dragenter');
92+
spectator.dispatchMouseEvent(byTestId('custom-drop-zone'), 'dragover', 0, 0, getDragEventWithDataTransfer('dragover'));
8493
spectator.dispatchMouseEvent('button', 'dragenter');
8594
spectator.dispatchMouseEvent(byTestId('custom-drop-zone'), 'dragleave');
8695
spectator.detectChanges();
@@ -90,14 +99,17 @@ describe('UiFileDropZoneDirective', () => {
9099

91100
it('should remove highlight when dropping files', () => {
92101
spectator.dispatchMouseEvent(byTestId('custom-drop-zone'), 'dragenter');
93-
spectator.dispatchMouseEvent(byTestId('custom-drop-zone'), 'drop');
102+
spectator.dispatchMouseEvent(byTestId('custom-drop-zone'), 'dragover', 0, 0, getDragEventWithDataTransfer('dragover'));
103+
expect(spectator.query(byTestId('custom-drop-zone'))).toHaveClass('ui-file-drop-zone-highlight');
104+
105+
spectator.dispatchMouseEvent(byTestId('custom-drop-zone'), 'drop', 0, 0, getDragEventWithDataTransfer('drop'));
94106
spectator.detectChanges();
95107

96108
expect(spectator.query(byTestId('custom-drop-zone'))).not.toHaveClass('ui-file-drop-zone-highlight');
97109
});
98110

99111
it('should call service with files that were dropped', () => {
100-
const mouseEvent = createMouseEvent('drop');
112+
const mouseEvent = getDragEventWithDataTransfer('drop');
101113

102114
spectator.dispatchMouseEvent(byTestId('custom-drop-zone'), 'drop', undefined, undefined, mouseEvent);
103115
spectator.detectChanges();
@@ -155,3 +167,12 @@ describe('UiFileDropZoneDirective', () => {
155167
});
156168
});
157169
});
170+
171+
const getDragEventWithDataTransfer = (type: 'dragover' | 'drop', containsFiles = true) => {
172+
const dataTransfer = new DataTransfer();
173+
if (containsFiles) {
174+
const file = new File([''], 'file.jog');
175+
dataTransfer.items.add(file);
176+
}
177+
return new DragEvent(type, { dataTransfer });
178+
};

projects/angular/directives/ui-file-drop-zone/src/ui-file-drop-zone.directive.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,28 @@ export class UiFileDropZoneDirective implements OnInit, AfterViewInit, OnDestroy
6363
e.stopPropagation();
6464
e.preventDefault();
6565
this._dragCount -= 1;
66-
this._clearDropZoneHighlight();
67-
this.filesLoading.next(true);
68-
this._fileReaderService.processDroppedItems(e);
66+
const dragDataContainsFiles = this._dragEventContainsFiles(e);
67+
if (dragDataContainsFiles) {
68+
this._clearDropZoneHighlight();
69+
this.filesLoading.next(true);
70+
this._fileReaderService.processDroppedItems(e);
71+
}
6972
}
7073

7174
@HostListener('dragover', ['$event'])
7275
dragover(e: DragEvent) {
7376
// preventDefault is needed to enable drop event
7477
e.preventDefault();
78+
const dragDataContainsFiles = this._dragEventContainsFiles(e);
79+
if (this._dragCount > 0 && dragDataContainsFiles) {
80+
this._highlightDropZone();
81+
}
7582
}
7683

7784
@HostListener('dragenter')
7885
dragenter() {
7986
if (!this.disabled) {
8087
this._dragCount += 1;
81-
this._highlightDropZone();
8288
}
8389
}
8490

@@ -136,4 +142,8 @@ export class UiFileDropZoneDirective implements OnInit, AfterViewInit, OnDestroy
136142
}
137143
this._dropZone.classList.remove(DROP_ZONE_HIGHLIGHT_CLASS);
138144
}
145+
146+
private _dragEventContainsFiles(e: DragEvent) {
147+
return e.dataTransfer?.types.includes('Files');
148+
}
139149
}

projects/angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@uipath/angular",
3-
"version": "15.1.3",
3+
"version": "15.1.4",
44
"license": "MIT",
55
"author": {
66
"name": "UiPath Inc",

0 commit comments

Comments
 (0)