@@ -17,31 +17,41 @@ import { DisplayDensityBase, DisplayDensityToken, IDisplayDensityOptions, Displa
1717 selector : '[igxButton]'
1818} )
1919export class IgxButtonDirective extends DisplayDensityBase {
20+
21+ /**
22+ *@hidden
23+ */
24+ private _type : string ;
25+
2026 /**
2127 *@hidden
2228 */
23- private _type = 'flat' ;
29+ private _defaultType = 'flat' ;
30+
2431 /**
2532 *@hidden
2633 */
27- private _cssClass = 'igx-button' ;
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,21 +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- if ( value && this . _type !== value ) {
79- this . _renderer . removeClass ( this . nativeElement , `${ this . _cssClass } --${ this . _type } ` ) ;
80- this . _type = value ;
81- 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 } ` ) ;
8296 }
8397 }
98+
8499 /**
85100 * Sets the button text color.
86101 * ```html
@@ -92,6 +107,7 @@ export class IgxButtonDirective extends DisplayDensityBase {
92107 this . _color = value || this . nativeElement . style . color ;
93108 this . _renderer . setStyle ( this . nativeElement , 'color' , this . _color ) ;
94109 }
110+
95111 /**
96112 * Sets the background color of the button.
97113 * ```html
@@ -103,6 +119,7 @@ export class IgxButtonDirective extends DisplayDensityBase {
103119 this . _backgroundColor = value || this . _backgroundColor ;
104120 this . _renderer . setStyle ( this . nativeElement , 'background' , this . _backgroundColor ) ;
105121 }
122+
106123 /**
107124 * Sets the `aria-label` attribute.
108125 * ```html
@@ -114,6 +131,7 @@ export class IgxButtonDirective extends DisplayDensityBase {
114131 this . _label = value || this . _label ;
115132 this . _renderer . setAttribute ( this . nativeElement , `aria-label` , this . _label ) ;
116133 }
134+
117135 /**
118136 * Enables/disables the button.
119137 * ```html
@@ -124,9 +142,9 @@ export class IgxButtonDirective extends DisplayDensityBase {
124142 @Input ( ) set disabled ( val ) {
125143 val = ! ! val ;
126144 if ( val ) {
127- this . _renderer . addClass ( this . nativeElement , `${ this . _cssClass } --disabled` ) ;
145+ this . _renderer . addClass ( this . nativeElement , `${ this . _cssClassPrefix } --disabled` ) ;
128146 } else {
129- this . _renderer . removeClass ( this . nativeElement , `${ this . _cssClass } --disabled` ) ;
147+ this . _renderer . removeClass ( this . nativeElement , `${ this . _cssClassPrefix } --disabled` ) ;
130148 }
131149 }
132150
0 commit comments