@@ -11,6 +11,7 @@ import {
1111
1212import { Focusable } from '../core/a11y/focus-key-manager' ;
1313import { coerceBooleanProperty } from '../core/coercion/boolean-property' ;
14+ import { MdThemeable } from '../core/style/themeable' ;
1415
1516export interface MdChipEvent {
1617 chip : MdChip ;
@@ -35,17 +36,14 @@ export interface MdChipEvent {
3536 '(click)' : '_handleClick($event)'
3637 }
3738} )
38- export class MdChip implements Focusable , OnInit , OnDestroy {
39+ export class MdChip extends MdThemeable implements Focusable , OnInit , OnDestroy {
3940
4041 /** Whether or not the chip is disabled. Disabled chips cannot be focused. */
4142 protected _disabled : boolean = null ;
4243
4344 /** Whether or not the chip is selected. */
4445 protected _selected : boolean = false ;
4546
46- /** The palette color of selected chips. */
47- protected _color : string = 'primary' ;
48-
4947 /** Emitted when the chip is focused. */
5048 onFocus = new EventEmitter < MdChipEvent > ( ) ;
5149
@@ -58,11 +56,15 @@ export class MdChip implements Focusable, OnInit, OnDestroy {
5856 /** Emitted when the chip is destroyed. */
5957 @Output ( ) destroy = new EventEmitter < MdChipEvent > ( ) ;
6058
61- constructor ( protected _renderer : Renderer , protected _elementRef : ElementRef ) { }
59+ constructor ( protected _renderer : Renderer , protected _elementRef : ElementRef ) {
60+ super ( _renderer , _elementRef ) ;
61+
62+ // By default the chip elements should use the primary palette.
63+ this . color = 'primary' ;
64+ }
6265
6366 ngOnInit ( ) : void {
6467 this . _addDefaultCSSClass ( ) ;
65- this . _updateColor ( this . _color ) ;
6668 }
6769
6870 ngOnDestroy ( ) : void {
@@ -108,15 +110,6 @@ export class MdChip implements Focusable, OnInit, OnDestroy {
108110 return this . selected ;
109111 }
110112
111- /** The color of the chip. Can be `primary`, `accent`, or `warn`. */
112- @Input ( ) get color ( ) : string {
113- return this . _color ;
114- }
115-
116- set color ( value : string ) {
117- this . _updateColor ( value ) ;
118- }
119-
120113 /** Allows for programmatic focusing of the chip. */
121114 focus ( ) : void {
122115 this . _renderer . invokeElementMethod ( this . _elementRef . nativeElement , 'focus' ) ;
@@ -148,17 +141,4 @@ export class MdChip implements Focusable, OnInit, OnDestroy {
148141 }
149142 }
150143
151- /** Updates the private _color variable and the native element. */
152- private _updateColor ( newColor : string ) {
153- this . _setElementColor ( this . _color , false ) ;
154- this . _setElementColor ( newColor , true ) ;
155- this . _color = newColor ;
156- }
157-
158- /** Sets the mat-color on the native element. */
159- private _setElementColor ( color : string , isAdd : boolean ) {
160- if ( color != null && color != '' ) {
161- this . _renderer . setElementClass ( this . _elementRef . nativeElement , `mat-${ color } ` , isAdd ) ;
162- }
163- }
164144}
0 commit comments