Skip to content

Commit

Permalink
Fix multiple emits on va-file-input-multiple (#1440)
Browse files Browse the repository at this point in the history
  • Loading branch information
ataker authored Dec 18, 2024
1 parent 2b9888e commit fde33e2
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 fde33e2

Please sign in to comment.