From c3a0638b2c17ac4f3e38487b590a21f3d5d8f30e Mon Sep 17 00:00:00 2001 From: allan-chagas-brisa Date: Fri, 20 Oct 2023 11:42:45 -0300 Subject: [PATCH 1/2] fix: values emittion when changing option --- .../input-select/input-select.component.html | 2 ++ .../input-select.component.spec.ts | 20 +++++++++++++++++++ .../input-select/input-select.component.ts | 5 +++++ 3 files changed, 27 insertions(+) diff --git a/projects/ion/src/lib/input-select/input-select.component.html b/projects/ion/src/lib/input-select/input-select.component.html index 88fded9dd..ec4a04208 100644 --- a/projects/ion/src/lib/input-select/input-select.component.html +++ b/projects/ion/src/lib/input-select/input-select.component.html @@ -38,6 +38,7 @@ [disabled]="disabled" [(ngModel)]="value" (ngModelChange)="handleChange()" + (blur)="handleChange()" /> @@ -53,6 +54,7 @@ [disabled]="disabled" [(ngModel)]="secondValue" (ngModelChange)="handleChange()" + (blur)="handleChange()" /> diff --git a/projects/ion/src/lib/input-select/input-select.component.spec.ts b/projects/ion/src/lib/input-select/input-select.component.spec.ts index 48d2547c2..065896b7e 100644 --- a/projects/ion/src/lib/input-select/input-select.component.spec.ts +++ b/projects/ion/src/lib/input-select/input-select.component.spec.ts @@ -179,6 +179,26 @@ describe('IonInputSelectComponent', () => { expect(valueChange).toHaveBeenCalledWith(valueToEmmit); }); + + it('should emit the event when another option is selected', async () => { + await sut({ + name: 'test', + valueChange: { emit: valueChange } as SafeAny, + }); + + valueToEmmit = { + optionSelected: { + label: 'Igual a', + selected: true, + }, + firstValue: '', + secondValue: '', + }; + + selectSecondOption(); + + expect(valueChange).toHaveBeenCalledWith(valueToEmmit); + }); }); describe('IonInputSelectComponent - Default options', () => { diff --git a/projects/ion/src/lib/input-select/input-select.component.ts b/projects/ion/src/lib/input-select/input-select.component.ts index 0a49e39e9..c5eb8437e 100644 --- a/projects/ion/src/lib/input-select/input-select.component.ts +++ b/projects/ion/src/lib/input-select/input-select.component.ts @@ -45,6 +45,11 @@ export class IonInputSelectComponent implements OnInit { this.clearInputs(); this.currentOption = selectedOption[0]; this.toggleDropdownVisibility(); + this.valueChange.emit({ + optionSelected: this.currentOption, + firstValue: this.value, + secondValue: this.secondValue, + }); } public handleClick(): void { From 374cd786d270726e2cd65b715f9d21d0a91d1523 Mon Sep 17 00:00:00 2001 From: allan-chagas-brisa Date: Fri, 20 Oct 2023 16:23:06 -0300 Subject: [PATCH 2/2] fix: blur emittion removed --- projects/ion/src/lib/input-select/input-select.component.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/projects/ion/src/lib/input-select/input-select.component.html b/projects/ion/src/lib/input-select/input-select.component.html index ec4a04208..88fded9dd 100644 --- a/projects/ion/src/lib/input-select/input-select.component.html +++ b/projects/ion/src/lib/input-select/input-select.component.html @@ -38,7 +38,6 @@ [disabled]="disabled" [(ngModel)]="value" (ngModelChange)="handleChange()" - (blur)="handleChange()" /> @@ -54,7 +53,6 @@ [disabled]="disabled" [(ngModel)]="secondValue" (ngModelChange)="handleChange()" - (blur)="handleChange()" />