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(combo): considera p-remove-initial-filter junto ao p-filter-service #2314

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 @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
</po-combo>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down