Skip to content

Commit a8e1b54

Browse files
committed
Address comments
1 parent 951a5d7 commit a8e1b54

File tree

12 files changed

+153
-257
lines changed

12 files changed

+153
-257
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ <h4>Advanced</h4>
2525
<md-chip color="accent" selected="true">Selected/Colored</md-chip>
2626

2727
<md-chip color="warn" selected="true" *ngIf="visible"
28-
(destroy)="alert('chip destroyed')" (remove)="toggleVisible()">
29-
<md-icon mdChipRemove>cancel</md-icon>
28+
(destroy)="displayMessage('chip destroyed')" (remove)="toggleVisible()">
3029
With Events
30+
<md-icon mdChipRemove>cancel</md-icon>
3131
</md-chip>
3232
</md-chip-list>
33+
<div>{{message}}</div>
3334
</md-card-content>
3435
</md-card>
3536

@@ -44,17 +45,17 @@ <h4>Input Container</h4>
4445
<code>&lt;md-input-container&gt;</code>.
4546
</p>
4647

47-
<md-input-container mdChipListContainer>
48-
<md-chip-list mdPrefix #chipList>
48+
<md-input-container [floatPlaceholder]="people.length > 0 ? 'always' : 'auto'">
49+
<md-chip-list #chipList>
4950
<md-chip *ngFor="let person of people" [color]="color" [selectable]="selectable"
5051
[removable]="removable" (remove)="remove(person)">
5152
{{person.name}}
5253
<md-icon mdChipRemove>cancel</md-icon>
5354
</md-chip>
55+
<input mdInput placeholder="New Contributor..."
56+
[mdChipList]="chipList" (mdChipEnd)="add($event)"
57+
[separatorKeysCodes]="separatorKeysCodes" [mdChipListAddOnBlur]="addOnBlur" />
5458
</md-chip-list>
55-
<input mdInput placeholder="New Contributor..."
56-
[mdChipList] ="chipList" (chipAdded)="add($event)"
57-
[separatorKeys]="separatorKeys" [addOnBlur]="addOnBlur" />
5859
</md-input-container>
5960

6061
<p>

src/demo-app/chips/chips-demo.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@
2727

2828
.mat-chip-remove.mat-icon {
2929
font-size: 18px;
30+
width: 1em;
31+
height: 1em;
32+
vertical-align: middle;
3033
}
3134
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ export class ChipsDemo {
2222
selectable: boolean = true;
2323
removable: boolean = true;
2424
addOnBlur: boolean = true;
25+
message: string = '';
2526

2627
// Enter, comma, semi-colon
27-
separatorKeys = [ENTER, COMMA, 186];
28+
separatorKeysCodes = [ENTER, COMMA, 186];
2829

2930
people: Person[] = [
3031
{ name: 'Kara' },
@@ -42,16 +43,16 @@ export class ChipsDemo {
4243
{ name: 'Warn', color: 'warn' }
4344
];
4445

45-
alert(message: string): void {
46-
alert(message);
46+
displayMessage(message: string): void {
47+
this.message = message;
4748
}
4849

4950
add(event: MdChipInputEvent): void {
5051
let input = event.input;
5152
let value = event.value;
5253

5354
// Add our person
54-
if (value && value.trim() != '') {
55+
if ((value || '').trim()) {
5556
this.people.push({ name: value.trim() });
5657
}
5758

src/lib/chips/_chips-theme.scss

Lines changed: 25 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@
66
$mat-chip-font-size: 13px;
77
$mat-chip-line-height: 16px;
88

9+
@mixin mat-chips-theme-color($color) {
10+
@include mat-chips-color(mat-contrast($color, 500), mat-color($color, 500));
11+
}
12+
13+
@mixin mat-chips-color($foreground, $background) {
14+
background-color: $background;
15+
color: $foreground;
16+
17+
.mat-chip-remove {
18+
color: $foreground;
19+
opacity: 0.4;
20+
}
21+
22+
.mat-chip-remove:hover {
23+
opacity: 0.54;
24+
}
25+
}
926

1027
@mixin mat-chips-theme($theme) {
1128
$is-dark-theme: map-get($theme, is-dark);
@@ -30,9 +47,8 @@ $mat-chip-line-height: 16px;
3047

3148
$focus-color: mat-color($foreground, secondary-text);
3249

33-
.mat-chip:not(.mat-basic-chip) {
34-
background-color: $unselected-background;
35-
color: $unselected-foreground;
50+
.mat-chip {
51+
@include mat-chips-color($unselected-foreground, $unselected-background);
3652

3753
.mat-chip-focus-border {
3854
pointer-events: none;
@@ -42,87 +58,27 @@ $mat-chip-line-height: 16px;
4258
outline: none;
4359
border: 2px solid $focus-color;
4460
}
45-
46-
.mat-chip-remove {
47-
color: $unselected-foreground;
48-
opacity: 0.3;
49-
}
50-
51-
.mat-chip-remove:hover {
52-
opacity: 0.54;
53-
}
5461
}
5562

56-
.mat-chip.mat-chip-selected:not(.mat-basic-chip) {
57-
background-color: $selected-background;
58-
color: $selected-foreground;
59-
60-
.mat-chip-remove {
61-
color: $selected-foreground;
62-
opacity: 0.4;
63-
}
64-
65-
.mat-chip-remove:hover {
66-
opacity: 0.54;
67-
}
63+
.mat-chip.mat-chip-selected {
64+
@include mat-chips-color($selected-foreground, $selected-background);
6865

6966
&.mat-primary {
70-
background-color: mat-color($primary);
71-
color: mat-color($primary, default-contrast);
72-
}
73-
74-
&.mat-accent {
75-
background-color: mat-color($accent);
76-
color: mat-color($accent, default-contrast);
67+
@include mat-chips-theme-color($primary);
7768
}
7869

7970
&.mat-warn {
80-
background-color: mat-color($warn);
81-
color: mat-color($warn, default-contrast);
82-
83-
.mat-chip-remove {
84-
color: mat-contrast($primary, 500);
85-
opacity: 0.4;
86-
}
87-
88-
.mat-chip-remove:hover {
89-
opacity: 0.54;
90-
}
91-
71+
@include mat-chips-theme-color($warn);
9272
}
9373

9474
&.mat-accent {
95-
background-color: mat-color($accent, 500);
96-
color: mat-contrast($accent, 500);
97-
98-
.mat-chip-remove {
99-
color: mat-contrast($accent, 500);
100-
opacity: 0.4;
101-
}
102-
103-
.mat-chip-remove:hover {
104-
opacity: 0.54;
105-
}
106-
}
107-
108-
&.mat-warn {
109-
background-color: mat-color($warn, 500);
110-
color: mat-contrast($warn, 500);
111-
112-
.mat-chip-remove {
113-
color: mat-contrast($warn, 500);
114-
opacity: 0.4;
115-
}
116-
117-
.mat-chip-remove:hover {
118-
opacity: 0.54;
119-
}
75+
@include mat-chips-theme-color($accent);
12076
}
12177
}
12278
}
12379

12480
@mixin mat-chips-typography($config) {
125-
.mat-chip:not(.mat-basic-chip) {
81+
.mat-chip{
12682
font-size: $mat-chip-font-size;
12783
line-height: $mat-chip-line-height;
12884
}

src/lib/chips/chip-input.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('MdChipInput', () => {
4242
}));
4343

4444
describe('basic behavior', () => {
45-
it('emits the (chipAdded) on enter keyup', () => {
45+
it('emits the (chipEnd) on enter keyup', () => {
4646
let ENTER_EVENT = createKeyboardEvent('keydown', ENTER, inputNativeElement) as any;
4747

4848
spyOn(testChipInput, 'add');
@@ -53,7 +53,7 @@ describe('MdChipInput', () => {
5353
});
5454

5555
describe('[addOnBlur]', () => {
56-
it('allows (chipAdded) when true', () => {
56+
it('allows (chipEnd) when true', () => {
5757
spyOn(testChipInput, 'add');
5858

5959
testChipInput.addOnBlur = true;
@@ -63,7 +63,7 @@ describe('MdChipInput', () => {
6363
expect(testChipInput.add).toHaveBeenCalled();
6464
});
6565

66-
it('disallows (chipAdded) when false', () => {
66+
it('disallows (chipEnd) when false', () => {
6767
spyOn(testChipInput, 'add');
6868

6969
testChipInput.addOnBlur = false;
@@ -74,8 +74,8 @@ describe('MdChipInput', () => {
7474
});
7575
});
7676

77-
describe('[separatorKeys]', () => {
78-
it('does not emit (chipAdded) when a non-separator key is pressed', () => {
77+
describe('[separatorKeysCodes]', () => {
78+
it('does not emit (chipEnd) when a non-separator key is pressed', () => {
7979
let ENTER_EVENT = createKeyboardEvent('keydown', ENTER, inputNativeElement) as any;
8080
spyOn(testChipInput, 'add');
8181

@@ -86,7 +86,7 @@ describe('MdChipInput', () => {
8686
expect(testChipInput.add).not.toHaveBeenCalled();
8787
});
8888

89-
it('emits (chipAdded) when a custom separator keys is pressed', () => {
89+
it('emits (chipEnd) when a custom separator keys is pressed', () => {
9090
let COMMA_EVENT = createKeyboardEvent('keydown', COMMA, inputNativeElement) as any;
9191
spyOn(testChipInput, 'add');
9292

@@ -102,9 +102,9 @@ describe('MdChipInput', () => {
102102
@Component({
103103
template: `
104104
<md-chip-list>
105+
<input mdInput mdChipList [mdChipListAddOnBlur]="addOnBlur" [separatorKeysCodes]="separatorKeys"
106+
(mdChipEnd)="add($event)" />
105107
</md-chip-list>
106-
<input mdInput mdChipList [addOnBlur]="addOnBlur" [separatorKeys]="separatorKeys"
107-
(chipAdded)="add($event)" />
108108
`
109109
})
110110
class TestChipInput {

src/lib/chips/chip-input.ts

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {Directive, Output, EventEmitter, Renderer, ElementRef, Input} from '@angular/core';
1+
import {Directive, Output, EventEmitter, ElementRef, Input} from '@angular/core';
2+
import {coerceBooleanProperty} from '../core/coercion/boolean-property';
23
import {ENTER} from '../core/keyboard/keycodes';
34
import {MdChipList} from './chip-list';
45

@@ -20,66 +21,64 @@ export class MdChipInput {
2021
_chipList: MdChipList;
2122

2223
/** Register input for chip list */
23-
@Input()
24-
set mdChipList(value: MdChipList) {
24+
@Input('mdChipList')
25+
set chipList(value: MdChipList) {
2526
if (value) {
2627
this._chipList = value;
2728
this._chipList.registerInput(this._inputElement);
2829
}
2930
}
3031

3132
/**
32-
* Whether or not the chipAdded event will be emitted when the input is blurred.
33-
*
34-
* Default `false`.
33+
* Whether or not the chipEnd event will be emitted when the input is blurred.
3534
*/
36-
@Input() addOnBlur = false;
35+
@Input('mdChipListAddOnBlur')
36+
get addOnBlur() { return this._addOnBlur; }
37+
set addOnBlur(value) { this._addOnBlur = coerceBooleanProperty(value); }
38+
_addOnBlur: boolean = false;
3739

3840
/**
39-
* The list of key codes that will trigger a chipAdded event.
41+
* The list of key codes that will trigger a chipEnd event.
4042
*
4143
* Defaults to `[ENTER]`.
4244
*/
43-
@Input() separatorKeys: number[] = [ENTER];
45+
// TODO(tinayuangao): Support Set here
46+
@Input() separatorKeysCodes: number[] = [ENTER];
4447

4548
/** Emitted when a chip is to be added. */
46-
@Output() chipAdded = new EventEmitter<MdChipInputEvent>();
49+
@Output('mdChipEnd')
50+
chipEnd = new EventEmitter<MdChipInputEvent>();
51+
52+
@Input('matChipList')
53+
set matChipList(value: MdChipList) { this.chipList = value; }
54+
55+
@Input('matChipListAddOnBlur')
56+
get matAddOnBlur() { return this._addOnBlur; }
57+
set matAddOnBlur(value) { this.addOnBlur = value; }
4758

4859
/** The native input element to which this directive is attached. */
4960
protected _inputElement: HTMLInputElement;
5061

51-
constructor(protected _renderer: Renderer, protected _elementRef: ElementRef) {
62+
constructor(protected _elementRef: ElementRef) {
5263
this._inputElement = this._elementRef.nativeElement as HTMLInputElement;
5364
}
5465

55-
/**
56-
* Utility method to make host definition/tests more clear.
57-
*
58-
* @private
59-
*/
66+
/** Utility method to make host definition/tests more clear. */
6067
_keydown(event?: KeyboardEvent) {
61-
this._add(event);
68+
this._emitChipEnd(event);
6269
}
6370

64-
/**
65-
* Checks to see if the blur should emit the (chipAdded) event.
66-
*
67-
* @private
68-
*/
71+
/** Checks to see if the blur should emit the (chipEnd) event. */
6972
_blur() {
7073
if (this.addOnBlur) {
71-
this._add();
74+
this._emitChipEnd();
7275
}
7376
}
7477

75-
/**
76-
* Checks to see if the (chipAdded) event needs to be emitted.
77-
*
78-
* @private
79-
*/
80-
_add(event?: KeyboardEvent) {
81-
if (!event || this.separatorKeys.indexOf(event.keyCode) > -1) {
82-
this.chipAdded.emit({ input: this._inputElement, value: this._inputElement.value });
78+
/** Checks to see if the (chipEnd) event needs to be emitted. */
79+
_emitChipEnd(event?: KeyboardEvent) {
80+
if (!event || this.separatorKeysCodes.indexOf(event.keyCode) > -1) {
81+
this.chipEnd.emit({ input: this._inputElement, value: this._inputElement.value });
8382

8483
if (event) {
8584
event.preventDefault();

src/lib/chips/chip-list.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,12 @@ class StandardChipList {
331331
@Component({
332332
template: `
333333
<md-input-container>
334-
<md-chip-list mdPrefix #chipList>
334+
<md-chip-list #chipList>
335335
<md-chip>Chip 1</md-chip>
336336
<md-chip>Chip 1</md-chip>
337337
<md-chip>Chip 1</md-chip>
338+
<input mdInput name="test" [mdChipList]="chipList"/>
338339
</md-chip-list>
339-
<input mdInput name="test" [mdChipList]="chipList"/>
340340
</md-input-container>
341341
`
342342
})

0 commit comments

Comments
 (0)