11import { CommonModule , DOCUMENT } from '@angular/common' ;
22import {
3+ AfterViewInit ,
34 Component ,
45 ContentChild ,
56 ContentChildren ,
@@ -11,8 +12,8 @@ import {
1112 QueryList ,
1213 Inject ,
1314 Optional ,
14- AfterContentInit ,
15- Renderer2 ,
15+ OnDestroy ,
16+ ChangeDetectorRef ,
1617} from '@angular/core' ;
1718import { IgxHintDirective } from '../directives/hint/hint.directive' ;
1819import {
@@ -36,6 +37,7 @@ import { IInputResourceStrings } from '../core/i18n/input-resources';
3637import { CurrentResourceStrings } from '../core/i18n/resources' ;
3738
3839import { mkenum , PlatformUtil } from '../core/utils' ;
40+ import { Subject , Subscription } from 'rxjs' ;
3941
4042const IgxInputGroupTheme = mkenum ( {
4143 Material : 'material' ,
@@ -56,7 +58,7 @@ export type IgxInputGroupTheme = (typeof IgxInputGroupTheme)[keyof typeof IgxInp
5658 { provide : IgxInputGroupBase , useExisting : IgxInputGroupComponent } ,
5759 ] ,
5860} )
59- export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInputGroupBase , AfterContentInit {
61+ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInputGroupBase , AfterViewInit , OnDestroy {
6062 /**
6163 * Sets the resource strings.
6264 * By default it uses EN resources.
@@ -137,7 +139,9 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
137139
138140 private _type : IgxInputGroupType = null ;
139141 private _filled = false ;
140- private _variant : IgxInputGroupTheme ;
142+ private _theme : IgxInputGroupTheme ;
143+ private _theme$ = new Subject ( ) ;
144+ private _subscription : Subscription ;
141145 private _resourceStrings = CurrentResourceStrings . InputResStrings ;
142146
143147 /** @hidden */
@@ -214,13 +218,13 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
214218 * }
215219 */
216220 @Input ( )
217- public set theme ( variant : IgxInputGroupTheme ) {
218- this . _variant = variant ;
221+ public set theme ( value : IgxInputGroupTheme ) {
222+ this . _theme = value ;
219223 }
220224
221225 /**
222226 * Returns the theme of the input.
223- * The returned value is of tyep IgxInputGroupType.
227+ * The returned value is of type IgxInputGroupType.
224228 * ```typescript
225229 * @ViewChild ("MyInputGroup")
226230 * public inputGroup: IgxInputGroupComponent;
@@ -229,7 +233,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
229233 * }
230234 */
231235 public get theme ( ) : IgxInputGroupTheme {
232- return this . _variant ;
236+ return this . _theme ;
233237 }
234238
235239 constructor (
@@ -242,10 +246,15 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
242246 private _inputGroupType : IgxInputGroupType ,
243247 @Inject ( DOCUMENT )
244248 private document : any ,
245- private renderer : Renderer2 ,
246- private platform : PlatformUtil
249+ private platform : PlatformUtil ,
250+ private cdr : ChangeDetectorRef
247251 ) {
248252 super ( _displayDensityOptions ) ;
253+
254+ this . _subscription = this . _theme$ . asObservable ( ) . subscribe ( value => {
255+ this . _theme = value as IgxInputGroupTheme ;
256+ this . cdr . detectChanges ( ) ;
257+ } ) ;
249258 }
250259
251260 /** @hidden */
@@ -273,19 +282,6 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
273282 event . stopPropagation ( ) ;
274283 }
275284
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- }
289285 /**
290286 * Returns whether the `IgxInputGroupComponent` has hints.
291287 * ```typescript
@@ -313,7 +309,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
313309 public get hasBorder ( ) {
314310 return (
315311 ( this . type === 'line' || this . type === 'box' ) &&
316- this . _variant === 'material'
312+ this . _theme === 'material'
317313 ) ;
318314 }
319315
@@ -328,7 +324,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
328324 * ```
329325 */
330326 public get isTypeLine ( ) : boolean {
331- return this . type === 'line' && this . _variant === 'material' ;
327+ return this . type === 'line' && this . _theme === 'material' ;
332328 }
333329
334330 /**
@@ -343,7 +339,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
343339 */
344340 @HostBinding ( 'class.igx-input-group--box' )
345341 public get isTypeBox ( ) {
346- return this . type === 'box' && this . _variant === 'material' ;
342+ return this . type === 'box' && this . _theme === 'material' ;
347343 }
348344
349345 /** @hidden @internal */
@@ -379,7 +375,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
379375 */
380376 @HostBinding ( 'class.igx-input-group--border' )
381377 public get isTypeBorder ( ) {
382- return this . type === 'border' && this . _variant === 'material' ;
378+ return this . type === 'border' && this . _theme === 'material' ;
383379 }
384380
385381 /**
@@ -394,7 +390,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
394390 */
395391 @HostBinding ( 'class.igx-input-group--fluent' )
396392 public get isTypeFluent ( ) {
397- return this . _variant === 'fluent' ;
393+ return this . _theme === 'fluent' ;
398394 }
399395
400396 /**
@@ -409,7 +405,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
409405 */
410406 @HostBinding ( 'class.igx-input-group--bootstrap' )
411407 public get isTypeBootstrap ( ) {
412- return this . _variant === 'bootstrap' ;
408+ return this . _theme === 'bootstrap' ;
413409 }
414410
415411 /**
@@ -424,7 +420,7 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
424420 */
425421 @HostBinding ( 'class.igx-input-group--indigo' )
426422 public get isTypeIndigo ( ) {
427- return this . _variant === 'indigo-design' ;
423+ return this . _theme === 'indigo-design' ;
428424 }
429425
430426 /**
@@ -451,6 +447,31 @@ export class IgxInputGroupComponent extends DisplayDensityBase implements IgxInp
451447 public set filled ( val ) {
452448 this . _filled = val ;
453449 }
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+ }
454475}
455476
456477/** @hidden */
0 commit comments