feat: disables the internal dropzone if multiple=false and an upload is in progress (#18847)

you need to clear the files/queue before trying to upload something else, unless multiple=true
This commit is contained in:
Jacob Overgaard
2025-03-27 15:20:36 +01:00
committed by GitHub
parent 47e09efec6
commit 52bf6bc412

View File

@@ -74,6 +74,16 @@ export class UmbInputDropzoneElement extends UmbFormControlMixin<UmbUploadableIt
protected _manager = new UmbDropzoneManager(this);
/**
* Determines if the dropzone should be disabled.
* If the dropzone is disabled, it will not accept any uploads.
* It is considered disabled if the `disabled` property is set or if `multiple` is set to `false` and there is already an upload in progress.
* @returns {boolean} True if the dropzone should not accept uploads, otherwise false.
*/
get #isDisabled(): boolean {
return this.disabled || (!this.multiple && this._progressItems.length > 0);
}
constructor() {
super();
@@ -107,7 +117,7 @@ export class UmbInputDropzoneElement extends UmbFormControlMixin<UmbUploadableIt
* Opens the file browse dialog.
*/
public browse(): void {
if (this.disabled) return;
if (this.#isDisabled) return;
this._dropzone?.browse();
}
@@ -119,7 +129,7 @@ export class UmbInputDropzoneElement extends UmbFormControlMixin<UmbUploadableIt
label=${this.label}
accept=${ifDefined(this.accept)}
?multiple=${this.multiple}
?disabled=${this.disabled}
?disabled=${this.#isDisabled}
?disallowFolderUpload=${this.disableFolderUpload}
@change=${this.onUpload}
@click=${this.#handleBrowse}>
@@ -132,7 +142,6 @@ export class UmbInputDropzoneElement extends UmbFormControlMixin<UmbUploadableIt
}
protected renderUploader() {
if (this.disabled) return nothing;
if (!this._progressItems?.length) return nothing;
return html`
@@ -209,7 +218,7 @@ export class UmbInputDropzoneElement extends UmbFormControlMixin<UmbUploadableIt
protected async onUpload(e: UUIFileDropzoneEvent) {
e.stopImmediatePropagation();
if (this.disabled) return;
if (this.#isDisabled) return;
if (!e.detail.files.length && !e.detail.folders.length) return;
const uploadables = this._manager.createTemporaryFiles(e.detail.files);
@@ -250,6 +259,11 @@ export class UmbInputDropzoneElement extends UmbFormControlMixin<UmbUploadableIt
width: 100%;
inset: 0;
backdrop-filter: opacity(1); /* Removes the built in blur effect */
&[disabled] {
opacity: 0.5;
pointer-events: none;
}
}
#uploader {