Skip to content

Commit

Permalink
fix(material/chips): chip input with autocomplete has both the select…
Browse files Browse the repository at this point in the history
…ed and the suggested values added

Fixes a bug in the Angular Material `chips` component where the autocomplete input
has both the selected and the suggested values added.
The input should only take the suggested value

Fixes angular#28852
  • Loading branch information
lsamboretrorabbit committed Apr 12, 2024
1 parent 1999e20 commit 8ef7519
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/material/chips/chip-input.ts
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {BACKSPACE, hasModifierKey} from '@angular/cdk/keycodes';
import {BACKSPACE, ENTER, hasModifierKey} from '@angular/cdk/keycodes';
import {
AfterContentInit,
Directive,
Expand Down Expand Up @@ -167,6 +167,10 @@ export class MatChipInput implements MatChipTextControl, AfterContentInit, OnCha
this._chipGrid._focusLastChip();
event.preventDefault();
return;
} else if (event.keyCode === ENTER) {
// Prevent adding both the search string and the selected suggestion
event.preventDefault();
return;
} else {
this._focusLastChipOnBackspace = false;
}
Expand Down

0 comments on commit 8ef7519

Please sign in to comment.