diff --git a/projects/ui/src/lib/components/po-field/po-input/po-input-base.component.ts b/projects/ui/src/lib/components/po-field/po-input/po-input-base.component.ts index dbe2b1d01..7811a509f 100644 --- a/projects/ui/src/lib/components/po-field/po-input/po-input-base.component.ts +++ b/projects/ui/src/lib/components/po-field/po-input/po-input-base.component.ts @@ -114,6 +114,15 @@ export abstract class PoInputBaseComponent implements ControlValueAccessor, Vali */ @Output('p-blur') blur: EventEmitter = new EventEmitter(); + /** + * @optional + * + * @description + * + * Evento disparado ao pressionar tecla enter. + */ + @Output('p-enter-click') enterClick: EventEmitter = new EventEmitter(); + /** * @optional * diff --git a/projects/ui/src/lib/components/po-field/po-input/po-input.component.html b/projects/ui/src/lib/components/po-field/po-input/po-input.component.html index b29e18b00..6aa0c273a 100644 --- a/projects/ui/src/lib/components/po-field/po-input/po-input.component.html +++ b/projects/ui/src/lib/components/po-field/po-input/po-input.component.html @@ -32,6 +32,7 @@ (click)="eventOnClick($event)" (focus)="eventOnFocus($event)" (input)="eventOnInput($event)" + (keyup.enter)="enterClick.emit($event.target)" />
diff --git a/projects/ui/src/lib/components/po-field/po-input/po-input.component.spec.ts b/projects/ui/src/lib/components/po-field/po-input/po-input.component.spec.ts index af1a6d3dd..02bdf9229 100644 --- a/projects/ui/src/lib/components/po-field/po-input/po-input.component.spec.ts +++ b/projects/ui/src/lib/components/po-field/po-input/po-input.component.spec.ts @@ -51,9 +51,11 @@ describe('PoInputComponent: ', () => { describe('Methods:', () => { describe('ngAfterViewInit:', () => { let inputFocus: jasmine.Spy; + let inputkeyup: jasmine.Spy; beforeEach(() => { inputFocus = spyOn(component, 'focus'); + inputkeyup = spyOn(component.enterClick, 'emit'); }); it('should call `focus` if autoFocus is true.', () => { @@ -67,6 +69,13 @@ describe('PoInputComponent: ', () => { component.ngAfterViewInit(); expect(inputFocus).not.toHaveBeenCalled(); }); + + it('should emit "keyup.enter" event when an Enter key is pressed', () => { + const enterEvent = new KeyboardEvent('keyup', { key: 'Enter' }); + component.enterClick.emit(enterEvent); + component.ngAfterViewInit(); + expect(inputkeyup).toHaveBeenCalled(); + }); }); });