I am using mat-chip-list
along with mat-autocomplete
by referring the official angular material example https://material.angular.io/components/chips/overview#chip-input and https://stackblitz.com/angular/arjnbxmepgn?file=src%2Fapp%2Fchips-autocomplete-example.html. The same template shown in the above example is here -
<mat-form-field class="example-chip-list">
<mat-chip-list #chipList aria-label="Fruit selection">
<mat-chip
*ngFor="let fruit of fruits"
[selectable]="selectable"
[removable]="removable"
(removed)="remove(fruit)">
{{fruit}}
<mat-icon matChipRemove *ngIf="removable">cancel</mat-icon>
</mat-chip>
<input
placeholder="New fruit..."
#fruitInput
[formControl]="fruitCtrl"
[matAutocomplete]="auto"
[matChipInputFor]="chipList"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
(matChipInputTokenEnd)="add($event)">
</mat-chip-list>
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">
<mat-option *ngFor="let fruit of filteredFruits | async" [value]="fruit">
{{fruit}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
It works fine except the following issue -
As soon as the user focuses the input, the MatAutoComplete
panel opens with suggestions. If the user enters a text which does not exist in the suggestions and presses the "ENTER" key, the entered text is visible in a Chip and it opens the MatAutoComplate
panel. I want to stop the opening of the MatAutoComplete
panel in such a case. I do not want to open the suggestion panel if the user enters an unknown text [i.e. text other than in suggestions]. The same case can be seen in https://stackblitz.com/angular/arjnbxmepgn?file=src%2Fapp%2Fchips-autocomplete-example.html.
If the user selects one of the options from the suggestions and presses the "ENTER" key, the MatAutoComplete
panel does not open. This is what I want in the scenario when the user enters an unknown text in the input and presses the "ENTER" key.
Any help will be highly appreciated.