Skip to content

Commit 031e15f

Browse files
crisbetojelbourn
authored andcommitted
docs(chips): chips autocomplete demo separator key codes not working correctly (#17558)
In #12971 `addOnBlur` was added to the chips autocomplete example, however it ended up breaking pressing the separator keys while the autocomplete is open. These changes remove the `addOnBlur` since having an autocomplete and adding chips on blur inherrently doesn't work together, because clicking on the autocomplete will blur the input. We could technically hack around it with a timeout, but that'll make the demo more confusing. Fixes #17448.
1 parent 438f7e4 commit 031e15f

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

src/material-examples/material/chips/chips-autocomplete/chips-autocomplete-example.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
[matAutocomplete]="auto"
1616
[matChipInputFor]="chipList"
1717
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
18-
[matChipInputAddOnBlur]="addOnBlur"
1918
(matChipInputTokenEnd)="add($event)">
2019
</mat-chip-list>
2120
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">

src/material-examples/material/chips/chips-autocomplete/chips-autocomplete-example.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export class ChipsAutocompleteExample {
1818
visible = true;
1919
selectable = true;
2020
removable = true;
21-
addOnBlur = true;
2221
separatorKeysCodes: number[] = [ENTER, COMMA];
2322
fruitCtrl = new FormControl();
2423
filteredFruits: Observable<string[]>;
@@ -35,24 +34,20 @@ export class ChipsAutocompleteExample {
3534
}
3635

3736
add(event: MatChipInputEvent): void {
38-
// Add fruit only when MatAutocomplete is not open
39-
// To make sure this does not conflict with OptionSelected Event
40-
if (!this.matAutocomplete.isOpen) {
41-
const input = event.input;
42-
const value = event.value;
37+
const input = event.input;
38+
const value = event.value;
4339

44-
// Add our fruit
45-
if ((value || '').trim()) {
46-
this.fruits.push(value.trim());
47-
}
48-
49-
// Reset the input value
50-
if (input) {
51-
input.value = '';
52-
}
40+
// Add our fruit
41+
if ((value || '').trim()) {
42+
this.fruits.push(value.trim());
43+
}
5344

54-
this.fruitCtrl.setValue(null);
45+
// Reset the input value
46+
if (input) {
47+
input.value = '';
5548
}
49+
50+
this.fruitCtrl.setValue(null);
5651
}
5752

5853
remove(fruit: string): void {

0 commit comments

Comments
 (0)