Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(input): adiciona evento tecla enter #1770

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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