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' ,
@@ -54,7 +56,7 @@ export type IgxInputGroupTheme = (typeof IgxInputGroupTheme)[keyof typeof IgxInp
54
56
templateUrl : 'input-group.component.html' ,
55
57
providers : [ { provide : IgxInputGroupBase , useExisting : IgxInputGroupComponent } ] ,
56
58
} )
57
- export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInputGroupBase , AfterContentInit {
59
+ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInputGroupBase , AfterViewInit , OnDestroy {
58
60
/**
59
61
* Sets the resource strings.
60
62
* By default it uses EN resources.
@@ -135,7 +137,9 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
135
137
136
138
private _type : IgxInputGroupType = null ;
137
139
private _filled = false ;
138
- private _variant : IgxInputGroupTheme ;
140
+ private _theme : IgxInputGroupTheme ;
141
+ private _theme$ = new Subject ( ) ;
142
+ private _subscription : Subscription ;
139
143
private _resourceStrings = CurrentResourceStrings . InputResStrings ;
140
144
141
145
/** @hidden */
@@ -212,13 +216,13 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
212
216
* }
213
217
*/
214
218
@Input ( )
215
- public set theme ( variant : IgxInputGroupTheme ) {
216
- this . _variant = variant ;
219
+ public set theme ( value : IgxInputGroupTheme ) {
220
+ this . _theme = value ;
217
221
}
218
222
219
223
/**
220
224
* Returns the theme of the input.
221
- * The returned value is of tyep IgxInputGroupType.
225
+ * The returned value is of type IgxInputGroupType.
222
226
* ```typescript
223
227
* @ViewChild ("MyInputGroup")
224
228
* public inputGroup: IgxInputGroupComponent;
@@ -227,7 +231,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
227
231
* }
228
232
*/
229
233
public get theme ( ) : IgxInputGroupTheme {
230
- return this . _variant ;
234
+ return this . _theme ;
231
235
}
232
236
233
237
constructor (
@@ -240,10 +244,15 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
240
244
private _inputGroupType : IgxInputGroupType ,
241
245
@Inject ( DOCUMENT )
242
246
private document : any ,
243
- private renderer : Renderer2 ,
244
- private platform : PlatformUtil
247
+ private platform : PlatformUtil ,
248
+ private cdr : ChangeDetectorRef
245
249
) {
246
250
super ( _displayDensityOptions ) ;
251
+
252
+ this . _subscription = this . _theme$ . asObservable ( ) . subscribe ( value => {
253
+ this . _theme = value as IgxInputGroupTheme ;
254
+ this . cdr . detectChanges ( ) ;
255
+ } ) ;
247
256
}
248
257
249
258
/** @hidden */
@@ -271,19 +280,6 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
271
280
event . stopPropagation ( ) ;
272
281
}
273
282
274
- /** @hidden @internal */
275
- public ngAfterContentInit ( ) {
276
- if ( ! this . theme ) {
277
- if ( this . platform . isIE ) {
278
- this . _variant = IgxInputGroupTheme . Material ;
279
- } else {
280
- this . _variant = this . document . defaultView
281
- . getComputedStyle ( this . element . nativeElement )
282
- . getPropertyValue ( '--theme' )
283
- . trim ( ) as IgxInputGroupTheme ;
284
- }
285
- }
286
- }
287
283
/**
288
284
* Returns whether the `IgxInputGroupComponent` has hints.
289
285
* ```typescript
@@ -311,7 +307,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
311
307
public get hasBorder ( ) {
312
308
return (
313
309
( this . type === 'line' || this . type === 'box' ) &&
314
- this . _variant === 'material'
310
+ this . _theme === 'material'
315
311
) ;
316
312
}
317
313
@@ -326,7 +322,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
326
322
* ```
327
323
*/
328
324
public get isTypeLine ( ) : boolean {
329
- return this . type === 'line' && this . _variant === 'material' ;
325
+ return this . type === 'line' && this . _theme === 'material' ;
330
326
}
331
327
332
328
/**
@@ -341,7 +337,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
341
337
*/
342
338
@HostBinding ( 'class.igx-input-group--box' )
343
339
public get isTypeBox ( ) {
344
- return this . type === 'box' && this . _variant === 'material' ;
340
+ return this . type === 'box' && this . _theme === 'material' ;
345
341
}
346
342
347
343
/** @hidden @internal */
@@ -377,7 +373,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
377
373
*/
378
374
@HostBinding ( 'class.igx-input-group--border' )
379
375
public get isTypeBorder ( ) {
380
- return this . type === 'border' && this . _variant === 'material' ;
376
+ return this . type === 'border' && this . _theme === 'material' ;
381
377
}
382
378
383
379
/**
@@ -392,7 +388,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
392
388
*/
393
389
@HostBinding ( 'class.igx-input-group--fluent' )
394
390
public get isTypeFluent ( ) {
395
- return this . _variant === 'fluent' ;
391
+ return this . _theme === 'fluent' ;
396
392
}
397
393
398
394
/**
@@ -407,7 +403,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
407
403
*/
408
404
@HostBinding ( 'class.igx-input-group--bootstrap' )
409
405
public get isTypeBootstrap ( ) {
410
- return this . _variant === 'bootstrap' ;
406
+ return this . _theme === 'bootstrap' ;
411
407
}
412
408
413
409
/**
@@ -422,7 +418,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
422
418
*/
423
419
@HostBinding ( 'class.igx-input-group--indigo' )
424
420
public get isTypeIndigo ( ) {
425
- return this . _variant === 'indigo-design' ;
421
+ return this . _theme === 'indigo-design' ;
426
422
}
427
423
428
424
/**
@@ -449,6 +445,31 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
449
445
public set filled ( val ) {
450
446
this . _filled = val ;
451
447
}
448
+
449
+ /** @hidden @internal */
450
+ public ngAfterViewInit ( ) {
451
+ if ( ! this . _theme ) {
452
+ if ( this . platform . isIE ) {
453
+ Promise . resolve ( ) . then ( ( ) => {
454
+ this . _theme$ . next ( IgxInputGroupTheme . Material ) ;
455
+ } ) ;
456
+ } else {
457
+ const cssProp = this . document . defaultView
458
+ . getComputedStyle ( this . element . nativeElement )
459
+ . getPropertyValue ( '--theme' )
460
+ . trim ( ) ;
461
+
462
+ Promise . resolve ( ) . then ( ( ) => {
463
+ this . _theme$ . next ( cssProp ) ;
464
+ } ) ;
465
+ }
466
+ }
467
+ }
468
+
469
+ /** @hidden @internal */
470
+ public ngOnDestroy ( ) {
471
+ this . _subscription . unsubscribe ( ) ;
472
+ }
452
473
}
453
474
454
475
/** @hidden */
0 commit comments