@@ -17,31 +17,41 @@ import { DisplayDensityBase, DisplayDensityToken, IDisplayDensityOptions, Displa
1717    selector : '[igxButton]' 
1818} ) 
1919export  class  IgxButtonDirective  extends  DisplayDensityBase  { 
20+ 
2021    /** 
2122     *@hidden  
2223     */ 
23-     private  _type  =  'flat' ; 
24+     private  _type : string ; 
25+ 
2426    /** 
2527     *@hidden  
2628     */ 
27-     private  _cssClass  =  'igx-button' ; 
29+     private  _defaultType  =  'flat' ; 
30+ 
31+     /** 
32+      *@hidden  
33+      */ 
34+     private  _cssClassPrefix  =  'igx-button' ; 
35+ 
2836    /** 
2937     *@hidden  
3038     */ 
3139    private  _color : string ; 
40+ 
3241    /** 
3342     *@hidden  
3443     */ 
3544    private  _label : string ; 
45+ 
3646    /** 
3747     *@hidden  
3848     */ 
3949    private  _backgroundColor : string ; 
4050
4151    constructor ( public  element : ElementRef ,  private  _renderer : Renderer2 , 
4252        @Optional ( )  @Inject ( DisplayDensityToken )  protected  _displayDensityOptions : IDisplayDensityOptions )  { 
43-              super ( _displayDensityOptions ) ; 
44-          } 
53+         super ( _displayDensityOptions ) ; 
54+     } 
4555
4656    /** 
4757     * Returns the underlying DOM element 
@@ -66,18 +76,26 @@ export class IgxButtonDirective extends DisplayDensityBase {
6676     * ``` 
6777     * @memberof  IgxButtonDirective 
6878     */ 
69-     @HostBinding ( 'attr.role' )  public  role  =  'button' ; 
79+     @HostBinding ( 'attr.role' ) 
80+     public  role  =  'button' ; 
81+ 
7082    /** 
7183     * Sets the type of the button. 
7284     * ```html 
7385     * <button  igxButton= "icon"></button> 
7486     * ``` 
7587     * @memberof  IgxButtonDirective 
7688     */ 
77-     @Input ( 'igxButton' )  set  type ( value : string )  { 
78-         this . _type  =  value  ||  this . _type ; 
79-         this . _renderer . addClass ( this . nativeElement ,  `${ this . _cssClass } ${ this . _type }  ) ; 
89+     @Input ( 'igxButton' ) 
90+     set  type ( value : string )  { 
91+         const  newValue  =  value  ? value  : this . _defaultType ; 
92+         if  ( this . _type  !==  newValue )  { 
93+             this . _renderer . removeClass ( this . nativeElement ,  `${ this . _cssClassPrefix } ${ this . _type }  ) ; 
94+             this . _type  =  newValue ; 
95+             this . _renderer . addClass ( this . nativeElement ,  `${ this . _cssClassPrefix } ${ this . _type }  ) ; 
96+         } 
8097    } 
98+ 
8199    /** 
82100     * Sets the button text color. 
83101     * ```html 
@@ -89,6 +107,7 @@ export class IgxButtonDirective extends DisplayDensityBase {
89107        this . _color  =  value  ||  this . nativeElement . style . color ; 
90108        this . _renderer . setStyle ( this . nativeElement ,  'color' ,  this . _color ) ; 
91109    } 
110+ 
92111    /** 
93112     * Sets the background color of the button. 
94113     * ```html 
@@ -100,6 +119,7 @@ export class IgxButtonDirective extends DisplayDensityBase {
100119        this . _backgroundColor  =  value  ||  this . _backgroundColor ; 
101120        this . _renderer . setStyle ( this . nativeElement ,  'background' ,  this . _backgroundColor ) ; 
102121    } 
122+ 
103123    /** 
104124     * Sets the `aria-label` attribute. 
105125     * ```html 
@@ -111,6 +131,7 @@ export class IgxButtonDirective extends DisplayDensityBase {
111131        this . _label  =  value  ||  this . _label ; 
112132        this . _renderer . setAttribute ( this . nativeElement ,  `aria-label` ,  this . _label ) ; 
113133    } 
134+ 
114135    /** 
115136     * Enables/disables the button. 
116137     *  ```html 
@@ -121,9 +142,9 @@ export class IgxButtonDirective extends DisplayDensityBase {
121142    @Input ( )  set  disabled ( val )  { 
122143        val  =  ! ! val ; 
123144        if  ( val )  { 
124-             this . _renderer . addClass ( this . nativeElement ,  `${ this . _cssClass }  ) ; 
145+             this . _renderer . addClass ( this . nativeElement ,  `${ this . _cssClassPrefix }  ) ; 
125146        }  else  { 
126-             this . _renderer . removeClass ( this . nativeElement ,  `${ this . _cssClass }  ) ; 
147+             this . _renderer . removeClass ( this . nativeElement ,  `${ this . _cssClassPrefix }  ) ; 
127148        } 
128149    } 
129150
0 commit comments