Skip to content

Commit

Permalink
feat(filter): add disabled property for filter dropdown. (#440)
Browse files Browse the repository at this point in the history
This is good when a user wants to disable an option within the filter dropdown. It can be done by setting FilterField disabled property to true
  • Loading branch information
T0MASD authored and dlabrecq committed Aug 6, 2018
1 parent 7a1904b commit 12a35ba
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/app/filter/example/filter-basic-example.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ export class FilterBasicExampleComponent implements OnInit {
id: 'day7',
value: 'Saturday'
}]
}, {
id: 'apples',
title: 'Apples',
placeholder: 'Filter by apples...',
type: FilterType.TEXT,
disabled: true
}] as FilterField[],
resultsCount: this.items.length,
appliedFilters: []
Expand Down
5 changes: 5 additions & 0 deletions src/app/filter/filter-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ export class FilterField {
* Set to true when a separator should be shown instead of a menu option
*/
separator?: boolean;

/**
* A flag indicating the field is disabled
*/
disabled?: boolean;
}
3 changes: 3 additions & 0 deletions src/app/filter/filter-fields.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ export class FilterFieldsComponent implements DoCheck, OnInit {
}

private isFieldDisabled(field: FilterField): boolean {
if (field.disabled) {
return true;
}
if (field.type === undefined || field.type === 'text') {
return false;
}
Expand Down
20 changes: 19 additions & 1 deletion src/app/filter/filter.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ describe('Filter component - ', () => {
id: 'day7',
value: 'Saturday'
}]
}, {
id: 'apples',
title: 'Apples',
placeholder: 'Filter by apples...',
type: FilterType.TEXT,
disabled: true
}] as FilterField[],
appliedFilters: [],
resultsCount: 5
Expand Down Expand Up @@ -152,7 +158,19 @@ describe('Filter component - ', () => {
fixture.detectChanges(); // Workaround to fix dropdown tests

let fields = element.querySelectorAll('.filter-field');
expect(fields.length).toBe(5);
expect(fields.length).toBe(6);
}));

it('should have correct number of disabled filter fields', fakeAsync(function() {
const element = fixture.nativeElement;

let button = element.querySelector('.filter-pf button');
button.click();
tick();
fixture.detectChanges(); // Workaround to fix dropdown tests

let fields = element.querySelectorAll('.filter-pf .disabled');
expect(fields.length).toBe(1);
}));

it('should have correct number of results', function() {
Expand Down

0 comments on commit 12a35ba

Please sign in to comment.