Skip to content

Commit d11e293

Browse files
authored
Revert "Revert "feat(material/chips): prevent chips from being delete… (#22235)
* Revert "Revert "feat(material/chips): prevent chips from being deleted when user holds backspace (#19700)"" This is a roll-forward of the original PR. We will need to resolve the issues in Google's code base that caused it to be reverted before merging again. This reverts commit 4381b8e. * fixup! Revert "Revert "feat(material/chips): prevent chips from being deleted when user holds backspace (#19700)"" * fixup! Revert "Revert "feat(material/chips): prevent chips from being deleted when user holds backspace (#19700)""
1 parent 662b751 commit d11e293

File tree

12 files changed

+462
-332
lines changed

12 files changed

+462
-332
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,15 @@ export class ChipsAutocompleteExample {
3434
}
3535

3636
add(event: MatChipInputEvent): void {
37-
const input = event.input;
38-
const value = event.value;
37+
const value = (event.value || '').trim();
3938

4039
// Add our fruit
41-
if ((value || '').trim()) {
42-
this.fruits.push(value.trim());
40+
if (value) {
41+
this.fruits.push(value);
4342
}
4443

45-
// Reset the input value
46-
if (input) {
47-
input.value = '';
48-
}
44+
// Clear the input value
45+
event.chipInput!.clear();
4946

5047
this.fruitCtrl.setValue(null);
5148
}

src/components-examples/material/chips/chips-input/chips-input-example.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,15 @@ export class ChipsInputExample {
2727
];
2828

2929
add(event: MatChipInputEvent): void {
30-
const input = event.input;
31-
const value = event.value;
30+
const value = (event.value || '').trim();
3231

3332
// Add our fruit
34-
if ((value || '').trim()) {
35-
this.fruits.push({name: value.trim()});
33+
if (value) {
34+
this.fruits.push({name: value});
3635
}
3736

38-
// Reset the input value
39-
if (input) {
40-
input.value = '';
41-
}
37+
// Clear the input value
38+
event.chipInput!.clear();
4239
}
4340

4441
remove(fruit: Fruit): void {

src/dev-app/chips/chips-demo.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {Component} from '@angular/core';
1111
import {MatChipInputEvent} from '@angular/material/chips';
1212
import {ThemePalette} from '@angular/material/core';
1313

14-
1514
export interface Person {
1615
name: string;
1716
}
@@ -61,17 +60,15 @@ export class ChipsDemo {
6160
}
6261

6362
add(event: MatChipInputEvent): void {
64-
const {input, value} = event;
63+
const value = (event.value || '').trim();
6564

6665
// Add our person
67-
if ((value || '').trim()) {
68-
this.people.push({ name: value.trim() });
66+
if (value) {
67+
this.people.push({ name: value });
6968
}
7069

71-
// Reset the input value
72-
if (input) {
73-
input.value = '';
74-
}
70+
// Clear the input value
71+
event.chipInput!.clear();
7572
}
7673

7774
remove(person: Person): void {

src/dev-app/mdc-chips/mdc-chips-demo.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,15 @@ export class MdcChipsDemo {
6161
}
6262

6363
add(event: MatChipInputEvent): void {
64-
const {input, value} = event;
64+
const value = (event.value || '').trim();
6565

6666
// Add our person
67-
if ((value || '').trim()) {
68-
this.people.push({ name: value.trim() });
67+
if (value) {
68+
this.people.push({ name: value });
6969
}
7070

71-
// Reset the input value
72-
if (input) {
73-
input.value = '';
74-
}
71+
// Clear the input value
72+
event.chipInput!.clear();
7573
}
7674

7775
remove(person: Person): void {

0 commit comments

Comments
 (0)