fix(filter): Removed placeholder from within dropdown, dropdown shows… · patternfly/patternfly-ng@0dac7f6 · GitHub
Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit 0dac7f6

Browse files
dtaylor113dlabrecq
authored andcommitted
fix(filter): Removed placeholder from within dropdown, dropdown shows current value (#449)
1 parent 37b8a88 commit 0dac7f6

8 files changed

Lines changed: 35 additions & 21 deletions

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

Lines changed: 4 additions & 11 deletions

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
.btn-default {
3434
background-color: @color-pf-white;
3535
background-image: none;
36-
color: @color-pf-black-500;
37-
font-style: italic;
38-
font-weight: 400;
36+
.placeholder {
37+
color: @color-pf-black-500;
38+
font-style: italic;
39+
font-weight: 400;
40+
}
3941
}
4042
.avatar {
4143
height: 20px;

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
ViewEncapsulation
99
} from '@angular/core';
1010

11-
import { cloneDeep, defaults, isEqual } from 'lodash';
11+
import { cloneDeep, defaults, find, isEqual } from 'lodash';
1212

1313
import { FilterConfig } from './filter-config';
1414
import { FilterEvent } from './filter-event';
@@ -117,12 +117,24 @@ export class FilterFieldsComponent implements DoCheck, OnInit {
117117
if (!fieldFound) {
118118
this._currentField = this.config.fields[0];
119119
this._currentValue = null;
120+
} else if (this._currentField.type === 'select' || this._currentField.type === 'typeahead') {
121+
// clear dropdown if there is no applied filter for it
122+
if (!this.getAppliedFilterByField(this._currentField)) {
123+
this._currentValue = null;
124+
}
120125
}
121126
if (this._currentValue === undefined) {
122127
this._currentValue = null;
123128
}
124129
}
125130

131+
protected getAppliedFilterByField(field: any): any {
132+
let foundFilter = find(this.config.appliedFilters, {
133+
field: field
134+
});
135+
return foundFilter;
136+
}
137+
126138
/**
127139
* Reset current field and value
128140
*/
@@ -238,7 +250,13 @@ export class FilterFieldsComponent implements DoCheck, OnInit {
238250

239251
private selectField(field: FilterField): void {
240252
this._currentField = field;
241-
this._currentValue = null;
253+
if (this._currentField.type === 'select' || this._currentField.type === 'typeahead') {
254+
// Restore selected value for dropdown if there is an applied filter for it
255+
let filterField: any = this.getAppliedFilterByField(this._currentField);
256+
this._currentValue = filterField ? filterField.value : null;
257+
} else {
258+
this._currentValue = null;
259+
}
242260
this.onFieldSelect.emit({
243261
field: this._currentField,
244262
value: this._currentValue
@@ -251,7 +269,7 @@ export class FilterFieldsComponent implements DoCheck, OnInit {
251269
query: filterQuery,
252270
value: filterQuery.value
253271
} as FilterEvent);
254-
this._currentValue = null;
272+
this._currentValue = filterQuery.value;
255273
}
256274

257275
private showDelete(): boolean {

src/app/filter/filter-results.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div class="row toolbar-pf-results">
44
<div [ngClass]="{'col-sm-9': config.totalCount !== undefined, 'col-sm-12': config.totalCount === undefined}">
55
<h5 *ngIf="config.appliedFilters.length > 0 && config.resultsCount >= 0">{{config.resultsCount}} Results</h5>
6-
<p *ngIf="config.appliedFilters.length > 0">Active filters:</p>
6+
<p *ngIf="config.appliedFilters.length > 0" class="filter-pf-active-label">Active filters:</p>
77
<ul class="list-inline">
88
<li *ngFor="let filter of config.appliedFilters">
99
<span class="active-filter label label-info">

src/app/filter/filter-results.component.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.filter-pf {
22
a { cursor: pointer; }
3+
.pficon-close {cursor: pointer; }
34
}
45

56
.pfng-save-filter-close {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ describe('Filter component - ', () => {
240240
fixture.detectChanges();
241241

242242
let items = element.querySelectorAll('.filter-select li');
243-
expect(items.length).toBe(config.fields[3].queries.length + 1); // +1 for the null value
243+
expect(items.length).toBe(config.fields[3].queries.length);
244244
}));
245245

246246
it('should clear a filter when the close button is clicked', function() {

src/app/table/basic-table/table.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ describe('Table component - ', () => {
486486
fixture.detectChanges(); // Workaround to fix dropdown tests
487487

488488
let items = element.querySelectorAll('.filter-select li');
489-
expect(items.length).toBe(config.toolbarConfig.filterConfig.fields[3].queries.length + 1); // +1 for the null value
489+
expect(items.length).toBe(config.toolbarConfig.filterConfig.fields[3].queries.length);
490490
}));
491491

492492
it('should clear a filter when the close button is clicked', function() {

src/app/toolbar/toolbar.component.spec.ts

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)