@@ -17,31 +17,41 @@ import { DisplayDensityBase, DisplayDensityToken, IDisplayDensityOptions, Displa
17
17
selector : '[igxButton]'
18
18
} )
19
19
export class IgxButtonDirective extends DisplayDensityBase {
20
+
20
21
/**
21
22
*@hidden
22
23
*/
23
- private _type = 'flat' ;
24
+ private _type : string ;
25
+
24
26
/**
25
27
*@hidden
26
28
*/
27
- private _cssClass = 'igx-button' ;
29
+ private _defaultType = 'flat' ;
30
+
31
+ /**
32
+ *@hidden
33
+ */
34
+ private _cssClassPrefix = 'igx-button' ;
35
+
28
36
/**
29
37
*@hidden
30
38
*/
31
39
private _color : string ;
40
+
32
41
/**
33
42
*@hidden
34
43
*/
35
44
private _label : string ;
45
+
36
46
/**
37
47
*@hidden
38
48
*/
39
49
private _backgroundColor : string ;
40
50
41
51
constructor ( public element : ElementRef , private _renderer : Renderer2 ,
42
52
@Optional ( ) @Inject ( DisplayDensityToken ) protected _displayDensityOptions : IDisplayDensityOptions ) {
43
- super ( _displayDensityOptions ) ;
44
- }
53
+ super ( _displayDensityOptions ) ;
54
+ }
45
55
46
56
/**
47
57
* Returns the underlying DOM element
@@ -66,18 +76,26 @@ export class IgxButtonDirective extends DisplayDensityBase {
66
76
* ```
67
77
* @memberof IgxButtonDirective
68
78
*/
69
- @HostBinding ( 'attr.role' ) public role = 'button' ;
79
+ @HostBinding ( 'attr.role' )
80
+ public role = 'button' ;
81
+
70
82
/**
71
83
* Sets the type of the button.
72
84
* ```html
73
85
* <button igxButton= "icon"></button>
74
86
* ```
75
87
* @memberof IgxButtonDirective
76
88
*/
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
+ }
80
97
}
98
+
81
99
/**
82
100
* Sets the button text color.
83
101
* ```html
@@ -89,6 +107,7 @@ export class IgxButtonDirective extends DisplayDensityBase {
89
107
this . _color = value || this . nativeElement . style . color ;
90
108
this . _renderer . setStyle ( this . nativeElement , 'color' , this . _color ) ;
91
109
}
110
+
92
111
/**
93
112
* Sets the background color of the button.
94
113
* ```html
@@ -100,6 +119,7 @@ export class IgxButtonDirective extends DisplayDensityBase {
100
119
this . _backgroundColor = value || this . _backgroundColor ;
101
120
this . _renderer . setStyle ( this . nativeElement , 'background' , this . _backgroundColor ) ;
102
121
}
122
+
103
123
/**
104
124
* Sets the `aria-label` attribute.
105
125
* ```html
@@ -111,6 +131,7 @@ export class IgxButtonDirective extends DisplayDensityBase {
111
131
this . _label = value || this . _label ;
112
132
this . _renderer . setAttribute ( this . nativeElement , `aria-label` , this . _label ) ;
113
133
}
134
+
114
135
/**
115
136
* Enables/disables the button.
116
137
* ```html
@@ -121,9 +142,9 @@ export class IgxButtonDirective extends DisplayDensityBase {
121
142
@Input ( ) set disabled ( val ) {
122
143
val = ! ! val ;
123
144
if ( val ) {
124
- this . _renderer . addClass ( this . nativeElement , `${ this . _cssClass } --disabled` ) ;
145
+ this . _renderer . addClass ( this . nativeElement , `${ this . _cssClassPrefix } --disabled` ) ;
125
146
} else {
126
- this . _renderer . removeClass ( this . nativeElement , `${ this . _cssClass } --disabled` ) ;
147
+ this . _renderer . removeClass ( this . nativeElement , `${ this . _cssClassPrefix } --disabled` ) ;
127
148
}
128
149
}
129
150
0 commit comments