Skip to content

Commit

Permalink
fix: Emit change event from form components (#523)
Browse files Browse the repository at this point in the history
fix: Emit change event
  • Loading branch information
ethanWallace authored May 13, 2024
1 parent f154fb2 commit d956370
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/web/src/components/gcds-checkbox/gcds-checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ export class GcdsCheckbox {
this.internals.setFormValue(null, 'checked');
}

const changeEvt = new e.constructor(e.type, e);
this.el.dispatchEvent(changeEvt);

this.gcdsChange.emit(this.checked);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ export class GcdsFileUploader {
}, 100);
}

if (e.type === 'change') {
const changeEvt = new e.constructor(e.type, e);
this.el.dispatchEvent(changeEvt);
}

customEvent.emit(this.value);
};

Expand Down
7 changes: 6 additions & 1 deletion packages/web/src/components/gcds-input/gcds-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,13 @@ export class GcdsInput {
this.value = val;
this.internals.setFormValue(val ? val : null);

if (e.type === 'change') {
const changeEvt = new e.constructor(e.type, e);
this.el.dispatchEvent(changeEvt);
}

customEvent.emit(this.value);
}
};

/**
* Emitted when the input has changed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ export class GcdsRadioGroup {
private onChange = e => {
this.gcdsChange.emit(e.target.value);
this.internals.setFormValue(e.target.value, 'checked');

const changeEvt = new e.constructor(e.type, e);
this.el.dispatchEvent(changeEvt);
};

/**
Expand Down
5 changes: 5 additions & 0 deletions packages/web/src/components/gcds-select/gcds-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ export class GcdsSelect {
this.value = val;
this.internals.setFormValue(val);

if (e.type === 'change') {
const changeEvt = new e.constructor(e.type, e);
this.el.dispatchEvent(changeEvt);
}

customEvent.emit(this.value);
};

Expand Down
7 changes: 6 additions & 1 deletion packages/web/src/components/gcds-textarea/gcds-textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,13 @@ export class GcdsTextarea {
this.value = val;
this.internals.setFormValue(val ? val : null);

if (e.type === 'change') {
const changeEvt = new e.constructor(e.type, e);
this.el.dispatchEvent(changeEvt);
}

customEvent.emit(this.value);
}
};

/**
* Call any active validators
Expand Down

0 comments on commit d956370

Please sign in to comment.