Skip to content

Commit

Permalink
Fix uploader not reading multiple property from the input element pro…
Browse files Browse the repository at this point in the history
…perly, closes #7276
  • Loading branch information
volkanceylan committed Oct 29, 2024
1 parent fd99166 commit bd8f0a7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
11 changes: 11 additions & 0 deletions packages/corelib/src/base/uploader.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Uploader } from "./uploader";

describe("Uploader", () => {
it("reads multiple from the input if not passed via options", () => {
const input = <input multiple={true} /> as HTMLInputElement;
const uploader = new Uploader({
input
});
expect(uploader["isMultiple"]?.()).toBe(true);
});
});
2 changes: 1 addition & 1 deletion packages/corelib/src/base/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class Uploader {
}

private isMultiple() {
return !!(this.opt.multiple ?? this.opt?.input?.getAttribute("multiple"));
return !!(this.opt.multiple ?? (this.opt?.input as HTMLInputElement)?.multiple);
}

private getTypePredicate(): ((type: string) => boolean) {
Expand Down
13 changes: 13 additions & 0 deletions packages/corelib/src/ui/helpers/uploadhelper.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { UploadHelper } from "./uploadhelper";

describe("UploadHelper.addUploadInput", () => {
it("should set inputs multiple attribute to true if options.allowMultiple is true", () => {
const container = document.body.appendChild(<div/>) as HTMLElement;
const input = UploadHelper.addUploadInput({
container,
inputName: "file",
allowMultiple: true
});
expect((input.getNode() as HTMLInputElement).multiple).toBe(true);
});
});
4 changes: 3 additions & 1 deletion packages/corelib/src/ui/helpers/uploadhelper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export namespace UploadHelper {
bar && (bar.style.width = (percent ?? 0).toString() + '%');
}

new Uploader({
var uploader = new Uploader({
batchSize: 1,
batchSuccess: data => {
const response: UploadResponse = data.response ?? {};
Expand Down Expand Up @@ -57,6 +57,8 @@ export namespace UploadHelper {
}
});

uploadInput.getNode()?.uploader = uploader;

return uploadInput;
}

Expand Down

0 comments on commit bd8f0a7

Please sign in to comment.