@@ -10,23 +10,22 @@ import {
10
10
Directive ,
11
11
Component ,
12
12
ContentChild ,
13
+ Directive ,
13
14
ElementRef ,
14
15
EventEmitter ,
15
16
Input ,
16
17
OnDestroy ,
17
18
Output ,
18
19
Renderer2 ,
20
+ forwardRef ,
19
21
} from '@angular/core' ;
20
22
21
- import { Observable } from 'rxjs/Observable' ;
22
23
import { Focusable } from '../core/a11y/focus-key-manager' ;
23
24
import { coerceBooleanProperty } from '@angular/cdk' ;
24
25
import { CanColor , mixinColor } from '../core/common-behaviors/color' ;
25
26
import { CanDisable , mixinDisabled } from '../core/common-behaviors/disabled' ;
26
27
import { SPACE , BACKSPACE , DELETE } from '../core/keyboard/keycodes' ;
27
28
28
- import { MdChipRemove } from './chip-remove' ;
29
-
30
29
export interface MdChipEvent {
31
30
chip : MdChip ;
32
31
}
@@ -70,7 +69,7 @@ export class MdBasicChip { }
70
69
} )
71
70
export class MdChip extends _MdChipMixinBase implements Focusable , OnDestroy , CanColor , CanDisable {
72
71
73
- @ContentChild ( MdChipRemove ) _chipRemove : MdChipRemove ;
72
+ @ContentChild ( forwardRef ( ( ) => MdChipRemove ) ) _chipRemove : MdChipRemove ;
74
73
75
74
/** Whether the chip is selected. */
76
75
@Input ( ) get selected ( ) : boolean { return this . _selected ; }
@@ -263,3 +262,44 @@ export class MdChip extends _MdChipMixinBase implements Focusable, OnDestroy, Ca
263
262
}
264
263
}
265
264
}
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
+ }
0 commit comments