Skip to content

Commit 17ea0a3

Browse files
committed
Move native input out of chip-list
1 parent 7aace99 commit 17ea0a3

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@ <h4>Input Container</h4>
4646
</p>
4747

4848
<md-input-container [floatPlaceholder]="people.length > 0 ? 'always' : 'auto'">
49-
<md-chip-list #chipList>
49+
<md-chip-list mdPrefix #chipList>
5050
<md-chip *ngFor="let person of people" [color]="color" [selectable]="selectable"
5151
[removable]="removable" (remove)="remove(person)">
5252
{{person.name}}
5353
<md-icon mdChipRemove>cancel</md-icon>
5454
</md-chip>
55-
<input mdInput placeholder="New Contributor..."
56-
[mdChipInputFor]="chipList"
57-
[mdChipInputSeparatorKeyCodes]="separatorKeysCodes"
58-
[mdChipInputAddOnBlur]="addOnBlur"
59-
(mdChipInputTokenEnd)="add($event)" />
6055
</md-chip-list>
56+
<input mdInput mdChipInput placeholder="New Contributor..."
57+
[mdChipInputFor]="chipList"
58+
[mdChipInputSeparatorKeyCodes]="separatorKeysCodes"
59+
[mdChipInputAddOnBlur]="addOnBlur"
60+
(mdChipInputTokenEnd)="add($event)" />
6161
</md-input-container>
6262

6363
<p>

src/lib/chips/chip-input.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Directive, Output, EventEmitter, ElementRef, Input} from '@angular/core';
22
import {coerceBooleanProperty} from '../core/coercion/boolean-property';
3-
import {ENTER} from '../core/keyboard/keycodes';
3+
import {ENTER, BACKSPACE} from '../core/keyboard/keycodes';
44
import {MdChipList} from './chip-list';
55

66
export interface MdChipInputEvent {
@@ -9,7 +9,7 @@ export interface MdChipInputEvent {
99
}
1010

1111
@Directive({
12-
selector: 'input[mdChipInputFor], input[matChipInputFor]',
12+
selector: 'input[mdChipInput], input[matChipInput]',
1313
host: {
1414
'class': 'mat-chip-input',
1515
'(keydown)': '_keydown($event)',
@@ -81,6 +81,9 @@ export class MdChipInput {
8181

8282
/** Checks to see if the (chipEnd) event needs to be emitted. */
8383
_emitChipEnd(event?: KeyboardEvent) {
84+
if (!this._inputElement.value && !!event && event.keyCode == BACKSPACE) {
85+
this._chipList.chips.last.focus();
86+
}
8487
if (!event || this.separatorKeyCodes.indexOf(event.keyCode) > -1) {
8588
this.chipEnd.emit({ input: this._inputElement, value: this._inputElement.value });
8689

src/lib/chips/chips.scss

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ $mat-chip-remove-size: 24px;
1313
$mat-chip-remove-font-size: 18px;
1414

1515
@mixin chip-margin() {
16+
[dir='rtl'] & {
17+
margin: $mat-chip-margin;
18+
}
19+
20+
[dir='ltr'] & {
21+
margin: $mat-chip-margin;
22+
}
23+
}
24+
25+
@mixin chip-margin-last() {
1626
[dir='rtl'] & {
1727
margin-left: 0;
1828
margin-right: $mat-chip-margin;
@@ -24,7 +34,7 @@ $mat-chip-remove-font-size: 18px;
2434
}
2535
}
2636

27-
@mixin chip-margin-reverse() {
37+
@mixin chip-margin-first() {
2838
[dir='ltr'] & {
2939
margin-left: 0;
3040
margin-right: $mat-chip-margin;
@@ -49,15 +59,18 @@ $mat-chip-remove-font-size: 18px;
4959
// Do not apply the special margins inside an input container
5060
// Remove the margin from the first element (in both LTR and RTL)
5161
&:first-child {
52-
@include chip-margin-reverse();
62+
@include chip-margin-first();
5363
}
5464

5565
// Remove the margin from the last element (in both LTR and RTL)
5666
&:last-child {
57-
@include chip-margin();
67+
@include chip-margin-last();
5868
}
5969
}
70+
}
6071

72+
.mat-input-container .mat-chip-list-wrapper .map-chip:last-child {
73+
@include chip-margin();
6174
}
6275

6376
.mat-input-prefix .mat-chip-list-wrapper {

0 commit comments

Comments
 (0)