Skip to content

Commit

Permalink
fix(ui5-file-uploader): adjust drop area (#8828)
Browse files Browse the repository at this point in the history
Issue:
- A file could be dragged over a very small transparent area representing
the inner input type file. That would mean that the same file couldn't be
dropped over the most of the visible ui5-file-uploader DOM.
Solution:
- Dragged files will be dropped over the root component area.

Fixes: #8572
  • Loading branch information
unazko committed May 10, 2024
1 parent c208132 commit cc7256a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/main/src/FileUploader.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
@keydown="{{_onkeydown}}"
@keyup="{{_onkeyup}}"
@click="{{_onclick}}"
@dragover="{{_ondrag}}"
@drop="{{_ondrop}}"
>
<div class="ui5-file-uploader-mask">
{{#unless hideInput}}
Expand Down
19 changes: 19 additions & 0 deletions packages/main/src/FileUploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,25 @@ class FileUploader extends UI5Element implements IFormElement {
}
}

_ondrag(e: DragEvent) {
e.preventDefault();
e.stopPropagation();
}

_ondrop(e: DragEvent) {
e.preventDefault();
e.stopPropagation();
const files = e.dataTransfer?.files;

if (files) {
this._input.files = files;
this._updateValue(files);
this.fireEvent<FileUploaderChangeEventDetail>("change", {
files,
});
}
}

_onfocusin() {
this.focused = true;
}
Expand Down

0 comments on commit cc7256a

Please sign in to comment.