Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit 12a35ba

Browse files
T0MASDdlabrecq
authored andcommitted
feat(filter): add disabled property for filter dropdown. (#440)
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
1 parent 7a1904b commit 12a35ba

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

src/app/filter/example/filter-basic-example.component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ export class FilterBasicExampleComponent implements OnInit {
142142
id: 'day7',
143143
value: 'Saturday'
144144
}]
145+
}, {
146+
id: 'apples',
147+
title: 'Apples',
148+
placeholder: 'Filter by apples...',
149+
type: FilterType.TEXT,
150+
disabled: true
145151
}] as FilterField[],
146152
resultsCount: this.items.length,
147153
appliedFilters: []

src/app/filter/filter-field.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@ export class FilterField {
3333
* Set to true when a separator should be shown instead of a menu option
3434
*/
3535
separator?: boolean;
36+
37+
/**
38+
* A flag indicating the field is disabled
39+
*/
40+
disabled?: boolean;
3641
}

src/app/filter/filter-fields.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ export class FilterFieldsComponent implements DoCheck, OnInit {
220220
}
221221

222222
private isFieldDisabled(field: FilterField): boolean {
223+
if (field.disabled) {
224+
return true;
225+
}
223226
if (field.type === undefined || field.type === 'text') {
224227
return false;
225228
}

src/app/filter/filter.component.spec.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ describe('Filter component - ', () => {
114114
id: 'day7',
115115
value: 'Saturday'
116116
}]
117+
}, {
118+
id: 'apples',
119+
title: 'Apples',
120+
placeholder: 'Filter by apples...',
121+
type: FilterType.TEXT,
122+
disabled: true
117123
}] as FilterField[],
118124
appliedFilters: [],
119125
resultsCount: 5
@@ -152,7 +158,19 @@ describe('Filter component - ', () => {
152158
fixture.detectChanges(); // Workaround to fix dropdown tests
153159

154160
let fields = element.querySelectorAll('.filter-field');
155-
expect(fields.length).toBe(5);
161+
expect(fields.length).toBe(6);
162+
}));
163+
164+
it('should have correct number of disabled filter fields', fakeAsync(function() {
165+
const element = fixture.nativeElement;
166+
167+
let button = element.querySelector('.filter-pf button');
168+
button.click();
169+
tick();
170+
fixture.detectChanges(); // Workaround to fix dropdown tests
171+
172+
let fields = element.querySelectorAll('.filter-pf .disabled');
173+
expect(fields.length).toBe(1);
156174
}));
157175

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

0 commit comments

Comments
 (0)