Skip to content

Commit 8143e18

Browse files
committed
sync test & address comments
1 parent f188183 commit 8143e18

File tree

8 files changed

+37
-61
lines changed

8 files changed

+37
-61
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ <h4>Input Container</h4>
5151
<md-chip *ngFor="let person of people" [color]="color" [selectable]="selectable"
5252
[removable]="removable" (remove)="remove(person)">
5353
{{person.name}}
54-
<md-icon mdChipRemove>cancel</md-icon>
54+
<md-icon mdChipRemove *ngIf="removable">cancel</md-icon>
5555
</md-chip>
5656
</md-chip-list>
5757
<input mdInput placeholder="New Contributor..."
@@ -72,7 +72,7 @@ <h4>Input Container</h4>
7272
<md-chip *ngFor="let person of people" [color]="color" [selectable]="selectable"
7373
[removable]="removable" (remove)="remove(person)">
7474
{{person.name}}
75-
<md-icon mdChipRemove>cancel</md-icon>
75+
<md-icon mdChipRemove *ngIf="removable">cancel</md-icon>
7676
</md-chip>
7777
</md-chip-list>
7878
<md-input-container>

src/lib/chips/_chips-theme.scss

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,8 @@ $mat-chip-line-height: 16px;
4545
$selected-background: if($is-dark-theme, mat-color($background, app-bar), #808080);
4646
$selected-foreground: if($is-dark-theme, mat-color($foreground, text), $light-selected-foreground);
4747

48-
$focus-color: mat-color($foreground, secondary-text);
49-
5048
.mat-chip {
5149
@include mat-chips-color($unselected-foreground, $unselected-background);
52-
53-
.mat-chip-focus-border {
54-
pointer-events: none;
55-
}
56-
57-
&:focus {
58-
outline: none;
59-
border: 2px solid $focus-color;
60-
}
6150
}
6251

6352
.mat-chip.mat-chip-selected {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import {Component, DebugElement} from '@angular/core';
44
import {MdChipInput, MdChipInputEvent} from './chip-input';
55
import {By} from '@angular/platform-browser';
66
import {Directionality} from '../core';
7-
import {createKeyboardEvent} from '../core/testing/event-objects';
7+
import {createKeyboardEvent} from '@angular/cdk/testing';
88

9-
import {ENTER, COMMA} from '../core/keyboard/keycodes';
9+
import {ENTER} from '../core/keyboard/keycodes';
10+
11+
const COMMA = 188;
1012

1113
describe('MdChipInput', () => {
1214
let fixture: ComponentFixture<any>;

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ import {async, ComponentFixture, TestBed, fakeAsync, tick} from '@angular/core/t
22
import {Component, DebugElement, QueryList} from '@angular/core';
33
import {By} from '@angular/platform-browser';
44
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
5-
import {MdChip, MdChipList, MdChipsModule} from './index';
5+
import {MdChipList, MdChipsModule} from './index';
66
import {FocusKeyManager} from '../core/a11y/focus-key-manager';
7-
import {SPACE, LEFT_ARROW, RIGHT_ARROW, TAB} from '../core/keyboard/keycodes';
87
import {createKeyboardEvent} from '@angular/cdk/testing';
98

109
import {MdInputModule} from '../input/index';
11-
import {LEFT_ARROW, RIGHT_ARROW, BACKSPACE, DELETE, SPACE, TAB} from '../core/keyboard/keycodes';
10+
import {LEFT_ARROW, RIGHT_ARROW, BACKSPACE, DELETE, TAB} from '../core/keyboard/keycodes';
1211
import {Directionality} from '../core';
1312

1413
describe('MdChipList', () => {
@@ -17,7 +16,7 @@ describe('MdChipList', () => {
1716
let chipListNativeElement: HTMLElement;
1817
let chipListInstance: MdChipList;
1918
let testComponent: StandardChipList;
20-
let chips: QueryList<MdChip>;
19+
let chips: QueryList<any>;
2120
let manager: FocusKeyManager;
2221

2322
let dir = 'ltr';

src/lib/chips/chip-list.ts

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,10 @@ import {
2222

2323
import {MdChip} from './chip';
2424
import {FocusKeyManager} from '../core/a11y/focus-key-manager';
25-
import {BACKSPACE, DELETE, SPACE, DOWN_ARROW, LEFT_ARROW, RIGHT_ARROW, UP_ARROW} from '../core/keyboard/keycodes';
25+
import {BACKSPACE, DELETE, LEFT_ARROW, RIGHT_ARROW, UP_ARROW} from '../core/keyboard/keycodes';
2626
import {coerceBooleanProperty, Directionality} from '@angular/cdk';
2727
import {Subscription} from 'rxjs/Subscription';
2828

29-
/** Utility to check if an input element has no value. */
30-
function _isInputEmpty(element: HTMLElement): boolean {
31-
if (element && element.nodeName.toLowerCase() == 'input') {
32-
let input = element as HTMLInputElement;
33-
34-
return !input.value;
35-
}
36-
37-
return false;
38-
}
39-
4029
/**
4130
* A material design chips component (named ChipList for it's similarity to the List component).
4231
*
@@ -116,7 +105,7 @@ export class MdChipList implements AfterContentInit, OnDestroy {
116105
this._subscribeChips(chips);
117106

118107
// If we have 0 chips, attempt to focus an input (if available)
119-
if (chips.length == 0) {
108+
if (chips.length === 0) {
120109
this._focusInput();
121110
}
122111

@@ -139,7 +128,10 @@ export class MdChipList implements AfterContentInit, OnDestroy {
139128
* it's selected state is always ignored.
140129
*/
141130
@Input()
142-
get selectable(): boolean { return this._selectable; }
131+
get selectable(): boolean {
132+
return this._selectable;
133+
}
134+
143135
set selectable(value: boolean) {
144136
this._selectable = coerceBooleanProperty(value);
145137
}
@@ -175,26 +167,19 @@ export class MdChipList implements AfterContentInit, OnDestroy {
175167
_keydown(event: KeyboardEvent) {
176168
let code = event.keyCode;
177169
let target = event.target as HTMLElement;
178-
let isInputEmpty = _isInputEmpty(target);
170+
let isInputEmpty = this._isInputEmpty(target);
179171
let isRtl = this._dir && this._dir.value == 'rtl';
180172

181-
let isPrevKey = (code == (isRtl ? RIGHT_ARROW : LEFT_ARROW));
182-
let isNextKey = (code == (isRtl ? LEFT_ARROW : RIGHT_ARROW));
183-
let isBackKey = (code == BACKSPACE || code == DELETE || code == UP_ARROW || isPrevKey);
184-
let isForwardKey = (code == DOWN_ARROW || isNextKey);
173+
let isPrevKey = (code === (isRtl ? RIGHT_ARROW : LEFT_ARROW));
174+
let isNextKey = (code === (isRtl ? LEFT_ARROW : RIGHT_ARROW));
175+
let isBackKey = (code === BACKSPACE || code == DELETE || code == UP_ARROW || isPrevKey);
185176
// If they are on an empty input and hit backspace/delete/left arrow, focus the last chip
186177
if (isInputEmpty && isBackKey) {
187178
this._keyManager.setLastItemActive();
188179
event.preventDefault();
189180
return;
190181
}
191182

192-
let focusedIndex = this._keyManager.activeItemIndex;
193-
194-
if (typeof focusedIndex === 'number' && this._isValidIndex(focusedIndex)) {
195-
let focusedChip: MdChip = this.chips.toArray()[focusedIndex];
196-
}
197-
198183
// If they are on a chip, check for space/left/right, otherwise pass to our key manager (like
199184
// up/down keys)
200185
if (target && target.classList.contains('mat-chip')) {
@@ -225,7 +210,7 @@ export class MdChipList implements AfterContentInit, OnDestroy {
225210
*/
226211
protected _updateTabIndex(): void {
227212
// If we have 0 chips, we should not allow keyboard focus
228-
this._tabIndex = (this.chips.length == 0 ? -1 : 0);
213+
this._tabIndex = (this.chips.length === 0 ? -1 : 0);
229214
}
230215

231216
/**
@@ -263,7 +248,7 @@ export class MdChipList implements AfterContentInit, OnDestroy {
263248
this._keyManager.setActiveItem(chipIndex - 1);
264249
}
265250
}
266-
if (this._keyManager.activeItemIndex == chipIndex) {
251+
if (this._keyManager.activeItemIndex === chipIndex) {
267252
this._lastDestroyedIndex = chipIndex;
268253
}
269254

@@ -308,4 +293,14 @@ export class MdChipList implements AfterContentInit, OnDestroy {
308293
private _isValidIndex(index: number): boolean {
309294
return index >= 0 && index < this.chips.length;
310295
}
296+
297+
private _isInputEmpty(element: HTMLElement): boolean {
298+
if (element && element.nodeName.toLowerCase() === 'input') {
299+
let input = element as HTMLInputElement;
300+
301+
return !input.value;
302+
}
303+
304+
return false;
305+
}
311306
}

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,6 @@ describe('Chip Remove', () => {
4848

4949
expect(testChip.didRemove).toHaveBeenCalled();
5050
});
51-
52-
it(`should monitors the parent chip's [removable] property`, () => {
53-
let hrefElement = chipNativeElement.querySelector('a')!;
54-
55-
testChip.removable = true;
56-
fixture.detectChanges();
57-
58-
expect(hrefElement.classList).not.toContain('mat-chip-remove-hidden');
59-
60-
testChip.removable = false;
61-
fixture.detectChanges();
62-
63-
expect(hrefElement.classList).toContain('mat-chip-remove-hidden');
64-
});
6551
});
6652
});
6753

src/lib/chips/chip.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
22
import {Component, DebugElement} from '@angular/core';
33
import {By} from '@angular/platform-browser';
4+
import {createKeyboardEvent} from '@angular/cdk/testing';
45
import {MdChipList, MdChip, MdChipEvent, MdChipsModule} from './index';
56
import {SPACE, DELETE, BACKSPACE} from '../core/keyboard/keycodes';
6-
import {createKeyboardEvent} from '../core/testing/event-objects';
77
import {Directionality} from '../core';
88

99
describe('Chips', () => {

src/lib/chips/chips.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
$mat-chip-vertical-padding: 8px;
44
$mat-chip-horizontal-padding: 12px;
5+
$mat-chip-remove-margin: -4px;
56

67
$mat-chips-chip-margin: $mat-chip-horizontal-padding / 4;
78

@@ -63,3 +64,7 @@ $mat-chips-chip-margin: $mat-chip-horizontal-padding / 4;
6364
.mat-input-prefix .mat-chip-list-wrapper {
6465
margin-bottom: $mat-chip-vertical-padding;
6566
}
67+
68+
.mat-chip-remove {
69+
margin: 0 $mat-chip-remove-margin 0 0;
70+
}

0 commit comments

Comments
 (0)