@@ -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' ;
2223import { Focusable } from '../core/a11y/focus-key-manager' ;
2324import { coerceBooleanProperty } from '@angular/cdk' ;
2425import { CanColor , mixinColor } from '../core/common-behaviors/color' ;
2526import { CanDisable , mixinDisabled } from '../core/common-behaviors/disabled' ;
2627import { SPACE , BACKSPACE , DELETE } from '../core/keyboard/keycodes' ;
2728
28- import { MdChipRemove } from './chip-remove' ;
29-
3029export interface MdChipEvent {
3130 chip : MdChip ;
3231}
@@ -70,7 +69,7 @@ export class MdBasicChip { }
7069} )
7170export 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+ }
0 commit comments