Skip to content

Commit 1f0f825

Browse files
AlexandraBuzilaedgarmueller
authored andcommitted
Editable combos don't show value list #1182
- show vale list on select, but keep filtering active on keytype
1 parent f0b516c commit 1f0f825

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import { startWith } from 'rxjs/operators/startWith';
7676
[id]="id"
7777
[formControl]="form"
7878
[matAutocomplete]="auto"
79+
(keyup)="updateFilter($event)"
7980
/>
8081
<mat-autocomplete
8182
autoActiveFirstOption
@@ -96,6 +97,7 @@ import { startWith } from 'rxjs/operators/startWith';
9697
export class AutocompleteControlRenderer extends JsonFormsControl {
9798
@Input() options: string[];
9899
filteredOptions: Observable<string[]>;
100+
shouldNotFilter: boolean;
99101

100102
constructor(ngRedux: NgRedux<JsonFormsState>) {
101103
super(ngRedux);
@@ -104,21 +106,34 @@ export class AutocompleteControlRenderer extends JsonFormsControl {
104106

105107
ngOnInit() {
106108
super.ngOnInit();
109+
this.shouldNotFilter = true;
107110
this.filteredOptions = this.form.valueChanges.pipe(
108111
startWith(''),
109112
map(val => this.filter(val))
110113
);
111114
}
112115

116+
updateFilter(event: any) {
117+
// ENTER
118+
if (event.keyCode === 13) {
119+
this.shouldNotFilter = true;
120+
} else {
121+
this.shouldNotFilter = false;
122+
}
123+
}
124+
113125
onSelect(ev: MatAutocompleteSelectedEvent) {
114126
const path = composeWithUi(this.uischema as ControlElement, this.path);
127+
this.shouldNotFilter = true;
115128
this.ngRedux.dispatch(Actions.update(path, () => ev.option.value));
116129
this.triggerValidation();
117130
}
118131

119132
filter(val: string): string[] {
120133
return (this.options || this.scopedSchema.enum || []).filter(
121-
option => !val || option.toLowerCase().indexOf(val.toLowerCase()) === 0
134+
option =>
135+
this.shouldNotFilter ||
136+
(!val || option.toLowerCase().indexOf(val.toLowerCase()) === 0)
122137
);
123138
}
124139
protected getOwnProps(): OwnPropsOfAutoComplete {

0 commit comments

Comments
 (0)