Skip to content

Commit

Permalink
Fix multiple emits on va-file-input-multiple
Browse files Browse the repository at this point in the history
  • Loading branch information
ataker committed Dec 17, 2024
1 parent 31d3ce2 commit c0ae0c9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ describe('va-file-input-multiple', () => {
await input
.uploadFile(filePath)
.catch(e => console.log('uploadFile error', e));

await page.waitForChanges();

expect(fileUploadSpy).toHaveReceivedEventTimes(1);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class VaFileInput {
}
};

private handleFile = (file: File) => {
private handleFile = (file: File, emitChange: boolean = true) => {
if (this.accept) {
const normalizedAcceptTypes = this.normalizeAcceptProp(this.accept);
if (!this.isAcceptedFileType(file.type, normalizedAcceptTypes)) {
Expand All @@ -156,7 +156,9 @@ export class VaFileInput {
}

this.file = file;
this.vaChange.emit({ files: [this.file] });
if (emitChange) {
this.vaChange.emit({ files: [this.file] });
}
this.uploadStatus = 'success';
this.internalError = null;
this.generateFileContents(this.file);
Expand Down Expand Up @@ -356,7 +358,7 @@ export class VaFileInput {
} = this;

if (value) {
this.handleFile(value);
this.handleFile(value, false);
}

const displayError = this.error || this.internalError;
Expand Down

0 comments on commit c0ae0c9

Please sign in to comment.