Skip to content

Commit 43b7c34

Browse files
tinayuangaojelbourn
authored andcommitted
demo(chips): Add snackbar notification for adding/removing chips (#6706)
1 parent d278796 commit 43b7c34

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/demo-app/a11y/chips/chips-a11y.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ <h2>Removable chips in a form field</h2>
2323

2424
<md-form-field>
2525
<md-chip-list mdPrefix #chipList>
26-
<md-chip *ngFor="let person of people" [color]="color">
26+
<md-chip *ngFor="let person of people" [color]="color" (remove)="remove(person)">
2727
{{person.name}}
28+
<md-icon mdChipRemove>cancel</md-icon>
2829
</md-chip>
2930
</md-chip-list>
3031
<input mdInput placeholder="New Contributor..."

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {MdChipInputEvent} from '@angular/material';
2+
import {MdChipInputEvent, MdSnackBar} from '@angular/material';
33

44

55
export interface Person {
@@ -29,6 +29,15 @@ export class ChipsAccessibilityDemo {
2929
{ name: 'Paul' }
3030
];
3131

32+
availableColors = [
33+
{ name: 'none', color: '' },
34+
{ name: 'Primary', color: 'primary' },
35+
{ name: 'Accent', color: 'accent' },
36+
{ name: 'Warn', color: 'warn' }
37+
];
38+
39+
constructor(public snackBar: MdSnackBar) {}
40+
3241
displayMessage(message: string): void {
3342
this.message = message;
3443
}
@@ -39,20 +48,24 @@ export class ChipsAccessibilityDemo {
3948

4049
// Add our person
4150
if ((value || '').trim()) {
42-
this.people.push({ name: value.trim() });
51+
const name = value.trim();
52+
this.people.push({ name: name });
53+
this.snackBar.open(`${name} added`, '', {duration: 2000});
4354
}
4455

4556
// Reset the input value
4657
if (input) {
4758
input.value = '';
4859
}
60+
4961
}
5062

5163
remove(person: Person): void {
5264
let index = this.people.indexOf(person);
5365

5466
if (index >= 0) {
5567
this.people.splice(index, 1);
68+
this.snackBar.open(`${person.name} deleted`, '', {duration: 2000});
5669
}
5770
}
5871

@@ -61,10 +74,4 @@ export class ChipsAccessibilityDemo {
6174
}
6275

6376

64-
availableColors = [
65-
{ name: 'none', color: '' },
66-
{ name: 'Primary', color: 'primary' },
67-
{ name: 'Accent', color: 'accent' },
68-
{ name: 'Warn', color: 'warn' }
69-
];
7077
}

0 commit comments

Comments
 (0)