From 508f31f86d8a41ed2d3a76e7ba3ea14aff3501a4 Mon Sep 17 00:00:00 2001 From: felipepetuco Date: Tue, 26 Nov 2024 17:00:05 -0300 Subject: [PATCH] feat(combo): considera p-remove-initial-filter junto ao p-filter-service --- .../po-dynamic-form-field.interface.ts | 10 ++++++++++ .../po-dynamic-form-fields.component.html | 1 + .../po-combo/po-combo.component.spec.ts | 17 +++++++++++++++++ .../po-field/po-combo/po-combo.component.ts | 5 ++++- 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-field.interface.ts b/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-field.interface.ts index ec7bdd9b6..18ceb800d 100644 --- a/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-field.interface.ts +++ b/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-field.interface.ts @@ -713,4 +713,14 @@ export interface PoDynamicFormField extends PoDynamicField { * **Componente compatível**: `po-upload` */ onUpload?: Function; + + /** + * + * Define que o filtro no primeiro clique será removido. + * + * > Caso o combo tenha um valor padrão de inicialização, o primeiro clique + * no componente retornará todos os itens da lista e não apenas o item inicialiazado. + * + */ + removeInitialFilter?: boolean; } diff --git a/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-fields/po-dynamic-form-fields.component.html b/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-fields/po-dynamic-form-fields.component.html index 72393f558..8d84edb5f 100644 --- a/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-fields/po-dynamic-form-fields.component.html +++ b/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-fields/po-dynamic-form-fields.component.html @@ -263,6 +263,7 @@ [p-disabled-tab-filter]="field.disabledTabFilter" [p-debounce-time]="field.debounceTime" [p-change-on-enter]="field.changeOnEnter" + [p-remove-initial-filter]="field.removeInitialFilter" > diff --git a/projects/ui/src/lib/components/po-field/po-combo/po-combo.component.spec.ts b/projects/ui/src/lib/components/po-field/po-combo/po-combo.component.spec.ts index cb7c05bb5..6126e30c2 100644 --- a/projects/ui/src/lib/components/po-field/po-combo/po-combo.component.spec.ts +++ b/projects/ui/src/lib/components/po-field/po-combo/po-combo.component.spec.ts @@ -171,6 +171,23 @@ describe('PoComboComponent:', () => { expect(fakeThis.applyFilter).toHaveBeenCalled(); }); + it('should reset filter when isFirstFilter is true and removeInitialFilter is true', () => { + const fakeThis = { + isFirstFilter: true, + removeInitialFilter: true, + selectedValue: true, + applyFilter: component.applyFilter, + setScrollingControl: component['setScrollingControl'] + }; + + spyOn(fakeThis, 'applyFilter'); + spyOn(fakeThis, 'setScrollingControl'); + component.applyFilterInFirstClick.call(fakeThis); + + expect(component.options).toEqual([]); + expect(fakeThis.applyFilter).toHaveBeenCalled(); + }); + it('shouldn`t call applyFilter', () => { const fakeThis = { isFirstFilter: true, 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 b2d57efe0..873379a27 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 @@ -445,7 +445,10 @@ export class PoComboComponent extends PoComboBaseComponent implements AfterViewI } applyFilterInFirstClick() { - if (this.isFirstFilter && !this.selectedValue) { + const shouldResetFilter = this.removeInitialFilter && this.isFirstFilter; + const isEmptyFirstFilter = this.isFirstFilter && !this.selectedValue; + + if (shouldResetFilter || isEmptyFirstFilter) { this.options = []; const scrollingControl = this.setScrollingControl(); this.applyFilter('', scrollingControl);