Skip to content

Commit

Permalink
feat(input): adicionando evento tecla enter
Browse files Browse the repository at this point in the history
O componente não escutava  evento keyup.enter. Este commit implementa evento tecla enter.

Fixes #1765, DTHFUI-7528
  • Loading branch information
FelipeDuarteLuna committed Aug 1, 2023
1 parent 7d140e3 commit e512c5c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ export abstract class PoInputBaseComponent implements ControlValueAccessor, Vali
*/
@Output('p-blur') blur: EventEmitter<any> = new EventEmitter();

/**
* @optional
*
* @description
*
* Evento disparado ao pressionar tecla enter.
*/
@Output('p-enter-click') enterClick: EventEmitter<any> = new EventEmitter();

/**
* @optional
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
(click)="eventOnClick($event)"
(focus)="eventOnFocus($event)"
(input)="eventOnInput($event)"
(keyup.enter)="enterClick.emit($event.target)"
/>

<div class="po-field-icon-container-right">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.', () => {
Expand All @@ -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();
});
});
});

Expand Down

0 comments on commit e512c5c

Please sign in to comment.