Skip to content

Commit 7aace99

Browse files
committed
Put MdChipRemove and MdChip in one file to avoid circular dependency
1 parent 1ff96d3 commit 7aace99

File tree

4 files changed

+46
-56
lines changed

4 files changed

+46
-56
lines changed

src/lib/chips/_chips-theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ $mat-chip-line-height: 16px;
7878
}
7979

8080
@mixin mat-chips-typography($config) {
81-
.mat-chip{
81+
.mat-chip {
8282
font-size: $mat-chip-font-size;
8383
line-height: $mat-chip-line-height;
8484
}

src/lib/chips/chip-remove.ts

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/lib/chips/chip.ts

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,22 @@ import {
1010
Directive,
1111
Component,
1212
ContentChild,
13+
Directive,
1314
ElementRef,
1415
EventEmitter,
1516
Input,
1617
OnDestroy,
1718
Output,
1819
Renderer2,
20+
forwardRef,
1921
} from '@angular/core';
2022

21-
import {Observable} from 'rxjs/Observable';
2223
import {Focusable} from '../core/a11y/focus-key-manager';
2324
import {coerceBooleanProperty} from '@angular/cdk';
2425
import {CanColor, mixinColor} from '../core/common-behaviors/color';
2526
import {CanDisable, mixinDisabled} from '../core/common-behaviors/disabled';
2627
import {SPACE, BACKSPACE, DELETE} from '../core/keyboard/keycodes';
2728

28-
import {MdChipRemove} from './chip-remove';
29-
3029
export interface MdChipEvent {
3130
chip: MdChip;
3231
}
@@ -70,7 +69,7 @@ export class MdBasicChip { }
7069
})
7170
export class MdChip extends _MdChipMixinBase implements Focusable, OnDestroy, CanColor, CanDisable {
7271

73-
@ContentChild(MdChipRemove) _chipRemove: MdChipRemove;
72+
@ContentChild(forwardRef(() => MdChipRemove)) _chipRemove: MdChipRemove;
7473

7574
/** Whether the chip is selected. */
7675
@Input() get selected(): boolean { return this._selected; }
@@ -263,3 +262,44 @@ export class MdChip extends _MdChipMixinBase implements Focusable, OnDestroy, Ca
263262
}
264263
}
265264
}
265+
266+
267+
/**
268+
* Applies proper (click) support and adds styling for use with the Material Design "cancel" icon
269+
* available at https://material.io/icons/#ic_cancel.
270+
*
271+
* Example:
272+
*
273+
* <md-chip>
274+
* <md-icon mdChipRemove>clear</md-icon>
275+
* </md-chip>
276+
*
277+
* You *may* use a custom icon, but you may need to override the `md-chip-remove` positioning styles
278+
* to properly center the icon within the chip.
279+
*/
280+
@Directive({
281+
selector: '[mdChipRemove], [matChipRemove]',
282+
host: {
283+
'class': 'mat-chip-remove',
284+
'[class.mat-chip-remove-hidden]': '!visible',
285+
'(click)': '_handleClick($event)'
286+
}
287+
})
288+
export class MdChipRemove {
289+
290+
/** Whether or not the remove icon is visible. */
291+
_isVisible: boolean = true;
292+
293+
@Input('mdChipRemoveVisible')
294+
get visible() { return this._isVisible; }
295+
set visible(value) {this._isVisible = coerceBooleanProperty(value);}
296+
297+
constructor(protected _parentChip: MdChip) {}
298+
299+
/** Calls the parent chip's public `remove()` method if applicable. */
300+
_handleClick(event: Event) {
301+
if (this._parentChip.removable) {
302+
this._parentChip.remove();
303+
}
304+
}
305+
}

src/lib/chips/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88

99
import {NgModule} from '@angular/core';
1010
import {MdChipList} from './chip-list';
11-
import {MdChip} from './chip';
11+
import {MdChip, MdChipRemove} from './chip';
1212
import {MdChipInput} from './chip-input';
13-
import {MdChipRemove} from './chip-remove';
1413

1514
export * from './chip-list';
1615
export * from './chip';
1716
export * from './chip-input';
18-
export * from './chip-remove';
1917

2018
@NgModule({
2119
imports: [],

0 commit comments

Comments
 (0)