From 9ece45dfb1d92cfa185b89e959f5d0491eddcb76 Mon Sep 17 00:00:00 2001 From: jcorrea97 Date: Tue, 31 Oct 2023 10:36:10 -0300 Subject: [PATCH] test(test): test --- .../po-field/po-combo/po-combo.component.html | 2 +- .../po-field/po-combo/po-combo.component.spec.ts | 10 ++++++++++ .../components/po-field/po-combo/po-combo.component.ts | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/projects/ui/src/lib/components/po-field/po-combo/po-combo.component.html b/projects/ui/src/lib/components/po-field/po-combo/po-combo.component.html index dd3209b90..db9bde061 100644 --- a/projects/ui/src/lib/components/po-field/po-combo/po-combo.component.html +++ b/projects/ui/src/lib/components/po-field/po-combo/po-combo.component.html @@ -38,7 +38,7 @@ *ngIf="clean && !disabled && inp.value" class="po-combo-clean" (click)="clear(); $event.preventDefault()" - (keydown.enter)="clear(); $event.preventDefault()" + (keydown.enter)="clearAndFocus(); $event.preventDefault()" > { expect(component.inputEl.nativeElement.focus).toHaveBeenCalled(); }); + it('should call inputEl.nativeElement and clear', () => { + spyOn(component.inputEl.nativeElement, 'focus'); + spyOn(component, 'clear'); + + component.clearAndFocus(); + + expect(component.inputEl.nativeElement.focus).toHaveBeenCalled(); + expect(component.clear).toHaveBeenCalled(); + }); + it('onOptionClick: should call `stopPropagation` if has an event parameter', () => { const option: PoComboOption = { value: 'value', label: 'label' }; diff --git a/projects/ui/src/lib/components/po-field/po-combo/po-combo.component.ts b/projects/ui/src/lib/components/po-field/po-combo/po-combo.component.ts index 490063166..7a79cb1a8 100644 --- a/projects/ui/src/lib/components/po-field/po-combo/po-combo.component.ts +++ b/projects/ui/src/lib/components/po-field/po-combo/po-combo.component.ts @@ -546,6 +546,11 @@ export class PoComboComponent extends PoComboBaseComponent implements AfterViewI this.applyFilter('', true); } + clearAndFocus() { + this.clear(null); + this.inputEl.nativeElement.focus(); + } + private adjustContainerPosition() { this.controlPosition.adjustPosition(poComboContainerPositionDefault); }