Skip to content

Commit 1e827b8

Browse files
fix(gcds-file-uploader): emit missing gcdsChange/change event (#896)
* fix(gcds-file-uploader): emit missing gcdsChange/change event * Update packages/web/src/components/gcds-file-uploader/gcds-file-uploader.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add composed: true to second change event --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent b7c74c0 commit 1e827b8

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

packages/web/src/components/gcds-file-uploader/gcds-file-uploader.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
Component,
33
Element,
4-
Event,
4+
Event as StencilEvent,
55
EventEmitter,
66
Prop,
77
Watch,
@@ -176,12 +176,12 @@ export class GcdsFileUploader {
176176
/**
177177
* Emitted when the uploader has focus.
178178
*/
179-
@Event() gcdsFocus!: EventEmitter<void>;
179+
@StencilEvent() gcdsFocus!: EventEmitter<void>;
180180

181181
/**
182182
* Emitted when the uploader loses focus.
183183
*/
184-
@Event() gcdsBlur!: EventEmitter<void>;
184+
@StencilEvent() gcdsBlur!: EventEmitter<void>;
185185

186186
private onBlur = () => {
187187
if (this.validateOn == 'blur') {
@@ -194,12 +194,12 @@ export class GcdsFileUploader {
194194
/**
195195
* Emitted when the user has made a file selection.
196196
*/
197-
@Event() gcdsChange: EventEmitter;
197+
@StencilEvent() gcdsChange: EventEmitter;
198198

199199
/**
200200
* Emitted when the user has uploaded a file.
201201
*/
202-
@Event() gcdsInput: EventEmitter;
202+
@StencilEvent() gcdsInput: EventEmitter;
203203

204204
private handleInput = (e, customEvent) => {
205205
const filesContainer: string[] = [];
@@ -232,7 +232,7 @@ export class GcdsFileUploader {
232232
/**
233233
* Remove file and update value.
234234
*/
235-
@Event() gcdsRemoveFile: EventEmitter;
235+
@StencilEvent() gcdsRemoveFile: EventEmitter;
236236
removeFile = e => {
237237
e.preventDefault();
238238
const fileName = e.target.closest('.file-uploader__uploaded-file')
@@ -259,6 +259,10 @@ export class GcdsFileUploader {
259259

260260
this.value = [...filesContainer];
261261
this.gcdsRemoveFile.emit(this.value);
262+
this.gcdsChange.emit(this.value);
263+
this.el.dispatchEvent(
264+
new Event('change', { bubbles: true, composed: true }),
265+
);
262266
};
263267

264268
/**
@@ -279,12 +283,12 @@ export class GcdsFileUploader {
279283
/**
280284
* Emitted when the input has a validation error.
281285
*/
282-
@Event() gcdsError!: EventEmitter<object>;
286+
@StencilEvent() gcdsError!: EventEmitter<object>;
283287

284288
/**
285289
* Emitted when the input has a validation error.
286290
*/
287-
@Event() gcdsValid!: EventEmitter<object>;
291+
@StencilEvent() gcdsValid!: EventEmitter<object>;
288292

289293
@Listen('submit', { target: 'document' })
290294
submitListener(e) {
@@ -345,6 +349,11 @@ export class GcdsFileUploader {
345349
this.shadowElement.files = dt.files;
346350
this.files = dt.files;
347351
}
352+
353+
this.gcdsChange.emit(this.value);
354+
this.el.dispatchEvent(
355+
new Event('change', { bubbles: true, composed: true }),
356+
);
348357
}
349358

350359
// Focus file input after drop

0 commit comments

Comments
 (0)