Skip to content

Commit e512c5c

Browse files
feat(input): adicionando evento tecla enter
O componente não escutava evento keyup.enter. Este commit implementa evento tecla enter. Fixes #1765, DTHFUI-7528
1 parent 7d140e3 commit e512c5c

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

projects/ui/src/lib/components/po-field/po-input/po-input-base.component.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ export abstract class PoInputBaseComponent implements ControlValueAccessor, Vali
114114
*/
115115
@Output('p-blur') blur: EventEmitter<any> = new EventEmitter();
116116

117+
/**
118+
* @optional
119+
*
120+
* @description
121+
*
122+
* Evento disparado ao pressionar tecla enter.
123+
*/
124+
@Output('p-enter-click') enterClick: EventEmitter<any> = new EventEmitter();
125+
117126
/**
118127
* @optional
119128
*

projects/ui/src/lib/components/po-field/po-input/po-input.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
(click)="eventOnClick($event)"
3333
(focus)="eventOnFocus($event)"
3434
(input)="eventOnInput($event)"
35+
(keyup.enter)="enterClick.emit($event.target)"
3536
/>
3637

3738
<div class="po-field-icon-container-right">

projects/ui/src/lib/components/po-field/po-input/po-input.component.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ describe('PoInputComponent: ', () => {
5151
describe('Methods:', () => {
5252
describe('ngAfterViewInit:', () => {
5353
let inputFocus: jasmine.Spy;
54+
let inputkeyup: jasmine.Spy;
5455

5556
beforeEach(() => {
5657
inputFocus = spyOn(component, 'focus');
58+
inputkeyup = spyOn(component.enterClick, 'emit');
5759
});
5860

5961
it('should call `focus` if autoFocus is true.', () => {
@@ -67,6 +69,13 @@ describe('PoInputComponent: ', () => {
6769
component.ngAfterViewInit();
6870
expect(inputFocus).not.toHaveBeenCalled();
6971
});
72+
73+
it('should emit "keyup.enter" event when an Enter key is pressed', () => {
74+
const enterEvent = new KeyboardEvent('keyup', { key: 'Enter' });
75+
component.enterClick.emit(enterEvent);
76+
component.ngAfterViewInit();
77+
expect(inputkeyup).toHaveBeenCalled();
78+
});
7079
});
7180
});
7281

0 commit comments

Comments
 (0)