1
1
import { CommonModule , DOCUMENT } from '@angular/common' ;
2
2
import {
3
+ AfterViewInit ,
3
4
Component ,
4
5
ContentChild ,
5
6
ContentChildren ,
@@ -11,8 +12,8 @@ import {
11
12
QueryList ,
12
13
Inject ,
13
14
Optional ,
14
- AfterContentInit ,
15
- Renderer2 ,
15
+ OnDestroy ,
16
+ ChangeDetectorRef ,
16
17
} from '@angular/core' ;
17
18
import { IgxHintDirective } from '../directives/hint/hint.directive' ;
18
19
import {
@@ -36,6 +37,7 @@ import { IInputResourceStrings } from '../core/i18n/input-resources';
36
37
import { CurrentResourceStrings } from '../core/i18n/resources' ;
37
38
38
39
import { mkenum , PlatformUtil } from '../core/utils' ;
40
+ import { Subject , Subscription } from 'rxjs' ;
39
41
40
42
const IgxInputGroupTheme = mkenum ( {
41
43
Material : 'material' ,
@@ -56,7 +58,7 @@ export type IgxInputGroupTheme = (typeof IgxInputGroupTheme)[keyof typeof IgxInp
56
58
{ provide : IgxInputGroupBase , useExisting : IgxInputGroupComponent } ,
57
59
] ,
58
60
} )
59
- export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInputGroupBase , AfterContentInit {
61
+ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInputGroupBase , AfterViewInit , OnDestroy {
60
62
/**
61
63
* Sets the resource strings.
62
64
* By default it uses EN resources.
@@ -137,7 +139,9 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
137
139
138
140
private _type : IgxInputGroupType = null ;
139
141
private _filled = false ;
140
- private _variant : IgxInputGroupTheme ;
142
+ private _theme : IgxInputGroupTheme ;
143
+ private _theme$ = new Subject ( ) ;
144
+ private _subscription : Subscription ;
141
145
private _resourceStrings = CurrentResourceStrings . InputResStrings ;
142
146
143
147
/** @hidden */
@@ -214,13 +218,13 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
214
218
* }
215
219
*/
216
220
@Input ( )
217
- public set theme ( variant : IgxInputGroupTheme ) {
218
- this . _variant = variant ;
221
+ public set theme ( value : IgxInputGroupTheme ) {
222
+ this . _theme = value ;
219
223
}
220
224
221
225
/**
222
226
* Returns the theme of the input.
223
- * The returned value is of tyep IgxInputGroupType.
227
+ * The returned value is of type IgxInputGroupType.
224
228
* ```typescript
225
229
* @ViewChild ("MyInputGroup")
226
230
* public inputGroup: IgxInputGroupComponent;
@@ -229,7 +233,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
229
233
* }
230
234
*/
231
235
public get theme ( ) : IgxInputGroupTheme {
232
- return this . _variant ;
236
+ return this . _theme ;
233
237
}
234
238
235
239
constructor (
@@ -242,10 +246,15 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
242
246
private _inputGroupType : IgxInputGroupType ,
243
247
@Inject ( DOCUMENT )
244
248
private document : any ,
245
- private renderer : Renderer2 ,
246
- private platform : PlatformUtil
249
+ private platform : PlatformUtil ,
250
+ private cdr : ChangeDetectorRef
247
251
) {
248
252
super ( _displayDensityOptions ) ;
253
+
254
+ this . _subscription = this . _theme$ . asObservable ( ) . subscribe ( value => {
255
+ this . _theme = value as IgxInputGroupTheme ;
256
+ this . cdr . detectChanges ( ) ;
257
+ } ) ;
249
258
}
250
259
251
260
/** @hidden */
@@ -273,19 +282,6 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
273
282
event . stopPropagation ( ) ;
274
283
}
275
284
276
- /** @hidden @internal */
277
- public ngAfterContentInit ( ) {
278
- if ( ! this . theme ) {
279
- if ( this . platform . isIE ) {
280
- this . _variant = IgxInputGroupTheme . Material ;
281
- } else {
282
- this . _variant = this . document . defaultView
283
- . getComputedStyle ( this . element . nativeElement )
284
- . getPropertyValue ( '--theme' )
285
- . trim ( ) as IgxInputGroupTheme ;
286
- }
287
- }
288
- }
289
285
/**
290
286
* Returns whether the `IgxInputGroupComponent` has hints.
291
287
* ```typescript
@@ -313,7 +309,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
313
309
public get hasBorder ( ) {
314
310
return (
315
311
( this . type === 'line' || this . type === 'box' ) &&
316
- this . _variant === 'material'
312
+ this . _theme === 'material'
317
313
) ;
318
314
}
319
315
@@ -328,7 +324,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
328
324
* ```
329
325
*/
330
326
public get isTypeLine ( ) : boolean {
331
- return this . type === 'line' && this . _variant === 'material' ;
327
+ return this . type === 'line' && this . _theme === 'material' ;
332
328
}
333
329
334
330
/**
@@ -343,7 +339,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
343
339
*/
344
340
@HostBinding ( 'class.igx-input-group--box' )
345
341
public get isTypeBox ( ) {
346
- return this . type === 'box' && this . _variant === 'material' ;
342
+ return this . type === 'box' && this . _theme === 'material' ;
347
343
}
348
344
349
345
/** @hidden @internal */
@@ -379,7 +375,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
379
375
*/
380
376
@HostBinding ( 'class.igx-input-group--border' )
381
377
public get isTypeBorder ( ) {
382
- return this . type === 'border' && this . _variant === 'material' ;
378
+ return this . type === 'border' && this . _theme === 'material' ;
383
379
}
384
380
385
381
/**
@@ -394,7 +390,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
394
390
*/
395
391
@HostBinding ( 'class.igx-input-group--fluent' )
396
392
public get isTypeFluent ( ) {
397
- return this . _variant === 'fluent' ;
393
+ return this . _theme === 'fluent' ;
398
394
}
399
395
400
396
/**
@@ -409,7 +405,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
409
405
*/
410
406
@HostBinding ( 'class.igx-input-group--bootstrap' )
411
407
public get isTypeBootstrap ( ) {
412
- return this . _variant === 'bootstrap' ;
408
+ return this . _theme === 'bootstrap' ;
413
409
}
414
410
415
411
/**
@@ -424,7 +420,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
424
420
*/
425
421
@HostBinding ( 'class.igx-input-group--indigo' )
426
422
public get isTypeIndigo ( ) {
427
- return this . _variant === 'indigo-design' ;
423
+ return this . _theme === 'indigo-design' ;
428
424
}
429
425
430
426
/**
@@ -451,6 +447,31 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
451
447
public set filled ( val ) {
452
448
this . _filled = val ;
453
449
}
450
+
451
+ /** @hidden @internal */
452
+ public ngAfterViewInit ( ) {
453
+ if ( ! this . _theme ) {
454
+ if ( this . platform . isIE ) {
455
+ Promise . resolve ( ) . then ( ( ) => {
456
+ this . _theme$ . next ( IgxInputGroupTheme . Material ) ;
457
+ } ) ;
458
+ } else {
459
+ const cssProp = this . document . defaultView
460
+ . getComputedStyle ( this . element . nativeElement )
461
+ . getPropertyValue ( '--theme' )
462
+ . trim ( ) ;
463
+
464
+ Promise . resolve ( ) . then ( ( ) => {
465
+ this . _theme$ . next ( cssProp ) ;
466
+ } ) ;
467
+ }
468
+ }
469
+ }
470
+
471
+ /** @hidden @internal */
472
+ public ngOnDestroy ( ) {
473
+ this . _subscription . unsubscribe ( ) ;
474
+ }
454
475
}
455
476
456
477
/** @hidden */
0 commit comments