Skip to content

Commit 8ef7519

Browse files
fix(material/chips): chip input with autocomplete has both the selected 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 #28852
1 parent 1999e20 commit 8ef7519

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/material/chips/chip-input.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {BACKSPACE, hasModifierKey} from '@angular/cdk/keycodes';
9+
import {BACKSPACE, ENTER, hasModifierKey} from '@angular/cdk/keycodes';
1010
import {
1111
AfterContentInit,
1212
Directive,
@@ -167,6 +167,10 @@ export class MatChipInput implements MatChipTextControl, AfterContentInit, OnCha
167167
this._chipGrid._focusLastChip();
168168
event.preventDefault();
169169
return;
170+
} else if (event.keyCode === ENTER) {
171+
// Prevent adding both the search string and the selected suggestion
172+
event.preventDefault();
173+
return;
170174
} else {
171175
this._focusLastChipOnBackspace = false;
172176
}

0 commit comments

Comments
 (0)