From e512c5c14282bd49b4cd76c1071a8667e24ed444 Mon Sep 17 00:00:00 2001 From: FelipeDuarteLuna Date: Tue, 25 Jul 2023 20:42:49 -0300 Subject: [PATCH] feat(input): adicionando evento tecla enter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit O componente não escutava evento keyup.enter. Este commit implementa evento tecla enter. Fixes #1765, DTHFUI-7528 --- .../po-field/po-input/po-input-base.component.ts | 9 +++++++++ .../components/po-field/po-input/po-input.component.html | 1 + .../po-field/po-input/po-input.component.spec.ts | 9 +++++++++ 3 files changed, 19 insertions(+) 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(); + }); }); });