Skip to content

Commit 3d2e528

Browse files
lsamboretrorabbitmmalerba
authored andcommitted
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 dc8f98e commit 3d2e528

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/material/chips/chip-input.ts

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

9+
import {_IdGenerator} from '@angular/cdk/a11y';
910
import {BACKSPACE, hasModifierKey} from '@angular/cdk/keycodes';
1011
import {
1112
Directive,
@@ -18,11 +19,10 @@ import {
1819
booleanAttribute,
1920
inject,
2021
} from '@angular/core';
21-
import {_IdGenerator} from '@angular/cdk/a11y';
22-
import {MatFormField, MAT_FORM_FIELD} from '@angular/material/form-field';
23-
import {MatChipsDefaultOptions, MAT_CHIPS_DEFAULT_OPTIONS} from './tokens';
22+
import {MAT_FORM_FIELD, MatFormField} from '@angular/material/form-field';
2423
import {MatChipGrid} from './chip-grid';
2524
import {MatChipTextControl} from './chip-text-control';
25+
import {MAT_CHIPS_DEFAULT_OPTIONS, MatChipsDefaultOptions} from './tokens';
2626

2727
/** Represents an input event on a `matChipInput`. */
2828
export interface MatChipInputEvent {
@@ -156,6 +156,9 @@ export class MatChipInput implements MatChipTextControl, OnChanges, OnDestroy {
156156
this._chipGrid._focusLastChip();
157157
}
158158
event.preventDefault();
159+
} else if (event.keyCode === ENTER) {
160+
// Prevent adding both the search string and the selected suggestion
161+
event.preventDefault();
159162
} else {
160163
this._emitChipEnd(event);
161164
}

0 commit comments

Comments
 (0)