Skip to content

Commit 1303781

Browse files
AlexandraBuzilaedgarmueller
authored andcommitted
Invert filter flag logic and update name #1182
- update filter on key down events, as the first key is otherwise ignored
1 parent 1f0f825 commit 1303781

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

packages/angular-material/src/controls/autocomplete.renderer.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ import { startWith } from 'rxjs/operators/startWith';
7676
[id]="id"
7777
[formControl]="form"
7878
[matAutocomplete]="auto"
79-
(keyup)="updateFilter($event)"
79+
(keydown)="updateFilter($event)"
8080
/>
8181
<mat-autocomplete
8282
autoActiveFirstOption
@@ -97,7 +97,7 @@ import { startWith } from 'rxjs/operators/startWith';
9797
export class AutocompleteControlRenderer extends JsonFormsControl {
9898
@Input() options: string[];
9999
filteredOptions: Observable<string[]>;
100-
shouldNotFilter: boolean;
100+
shouldFilter: boolean;
101101

102102
constructor(ngRedux: NgRedux<JsonFormsState>) {
103103
super(ngRedux);
@@ -106,7 +106,7 @@ export class AutocompleteControlRenderer extends JsonFormsControl {
106106

107107
ngOnInit() {
108108
super.ngOnInit();
109-
this.shouldNotFilter = true;
109+
this.shouldFilter = false;
110110
this.filteredOptions = this.form.valueChanges.pipe(
111111
startWith(''),
112112
map(val => this.filter(val))
@@ -116,23 +116,23 @@ export class AutocompleteControlRenderer extends JsonFormsControl {
116116
updateFilter(event: any) {
117117
// ENTER
118118
if (event.keyCode === 13) {
119-
this.shouldNotFilter = true;
119+
this.shouldFilter = false;
120120
} else {
121-
this.shouldNotFilter = false;
121+
this.shouldFilter = true;
122122
}
123123
}
124124

125125
onSelect(ev: MatAutocompleteSelectedEvent) {
126126
const path = composeWithUi(this.uischema as ControlElement, this.path);
127-
this.shouldNotFilter = true;
127+
this.shouldFilter = false;
128128
this.ngRedux.dispatch(Actions.update(path, () => ev.option.value));
129129
this.triggerValidation();
130130
}
131131

132132
filter(val: string): string[] {
133133
return (this.options || this.scopedSchema.enum || []).filter(
134134
option =>
135-
this.shouldNotFilter ||
135+
!this.shouldFilter ||
136136
(!val || option.toLowerCase().indexOf(val.toLowerCase()) === 0)
137137
);
138138
}

0 commit comments

Comments
 (0)