Skip to content

Commit 4381b8e

Browse files
committed
Revert "feat(material/chips): prevent chips from being deleted when user holds backspace (#19700)"
This reverts commit 6230560.
1 parent 85b5df6 commit 4381b8e

File tree

11 files changed

+332
-456
lines changed

11 files changed

+332
-456
lines changed

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

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

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

3940
// Add our fruit
40-
if (value) {
41-
this.fruits.push(value);
41+
if ((value || '').trim()) {
42+
this.fruits.push(value.trim());
4243
}
4344

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

4750
this.fruitCtrl.setValue(null);
4851
}

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

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

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

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

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

4144
remove(fruit: Fruit): void {

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

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

14+
1415
export interface Person {
1516
name: string;
1617
}
@@ -60,15 +61,17 @@ export class ChipsDemo {
6061
}
6162

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

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

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

7477
remove(person: Person): void {

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

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

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

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

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

7577
remove(person: Person): void {

0 commit comments

Comments
 (0)