Skip to content

Commit 5cf3559

Browse files
simeonoffkdinevrkaraivanov
authored
fix(input-group): theme CSS prop not retreived (#9505)
* fix(input-group): theme CSS prop not retrieved Co-authored-by: Konstantin Dinev <[email protected]> Co-authored-by: Radoslav Karaivanov <[email protected]>
1 parent f9cad3f commit 5cf3559

File tree

6 files changed

+85
-48
lines changed

6 files changed

+85
-48
lines changed

projects/igniteui-angular/src/lib/combo/combo.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<igx-combo-drop-down #igxComboDropDown class="igx-combo__drop-down" [displayDensity]="displayDensity"
3535
[width]="itemsWidth || '100%'" (onOpening)="handleOpening($event)" (onClosing)="handleClosing($event)"
3636
(onOpened)="handleOpened()" (onClosed)="handleClosed()">
37-
<igx-input-group *ngIf="displaySearchInput" [displayDensity]="displayDensity" class="igx-combo__search">
37+
<igx-input-group *ngIf="displaySearchInput" [displayDensity]="displayDensity" theme="material" class="igx-combo__search">
3838
<input class="igx-combo-input" igxInput #searchInput name="searchInput" autocomplete="off" type="text"
3939
[(ngModel)]="searchValue" (ngModelChange)="handleInputChange($event)" (keyup)="handleKeyUp($event)"
4040
(keydown)="handleKeyDown($event)" (focus)="dropdown.onBlur($event)" [attr.placeholder]="searchPlaceholder"

projects/igniteui-angular/src/lib/combo/combo.component.spec.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -803,12 +803,14 @@ describe('igxCombo', () => {
803803
]
804804
}).compileComponents();
805805
}));
806-
beforeEach(() => {
806+
beforeEach(fakeAsync(() => {
807807
fixture = TestBed.createComponent(IgxComboSampleComponent);
808808
fixture.detectChanges();
809809
combo = fixture.componentInstance.combo;
810810
input = fixture.debugElement.query(By.css(`.${CSS_CLASS_COMBO_INPUTGROUP}`));
811-
});
811+
tick();
812+
fixture.detectChanges();
813+
}));
812814
it('should initialize the combo component properly', () => {
813815
const toggleButton = fixture.debugElement.query(By.css('.' + CSS_CLASS_TOGGLEBUTTON));
814816
expect(fixture.componentInstance).toBeDefined();
@@ -1127,12 +1129,14 @@ describe('igxCombo', () => {
11271129
]
11281130
}).compileComponents();
11291131
}));
1130-
beforeEach(() => {
1132+
beforeEach(fakeAsync(() => {
11311133
fixture = TestBed.createComponent(IgxComboInContainerTestComponent);
11321134
fixture.detectChanges();
11331135
combo = fixture.componentInstance.combo;
11341136
containerElement = fixture.debugElement.query(By.css('.comboContainer')).nativeElement;
1135-
});
1137+
tick();
1138+
fixture.detectChanges();
1139+
}));
11361140
it('should adjust combo width to the container element width when set to 100%', () => {
11371141
const containerWidth = 500;
11381142
const comboWrapper = fixture.debugElement.query(By.css(CSS_CLASS_COMBO)).nativeElement;

projects/igniteui-angular/src/lib/grids/grid/grid-filtering-ui.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
242242
const reset = filterUIRow.queryAll(By.css('button'))[0];
243243
const close = filterUIRow.queryAll(By.css('button'))[1];
244244
const input = filterUIRow.query(By.directive(IgxInputDirective));
245+
tick();
245246

246247
expect(grid.rowList.length).toEqual(8);
247248

projects/igniteui-angular/src/lib/input-group/input-group.component.spec.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, ViewChild, ElementRef, Inject } from '@angular/core';
2-
import { TestBed, waitForAsync } from '@angular/core/testing';
2+
import { fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
33
import { By } from '@angular/platform-browser';
44
import { IgxInputGroupComponent, IgxInputGroupModule } from './input-group.component';
55
import { DisplayDensityToken, DisplayDensity } from '../core/displayDensity';
@@ -41,58 +41,69 @@ describe('IgxInputGroup', () => {
4141
.compileComponents();
4242
}));
4343

44-
it('Initializes an input group.', () => {
44+
it('Initializes an input group.', fakeAsync(() => {
4545
const fixture = TestBed.createComponent(InputGroupDisabledComponent);
4646
fixture.detectChanges();
4747

4848
const inputGroupElement = fixture.debugElement.query(By.css('igx-input-group')).nativeElement;
4949
expect(inputGroupElement.classList.contains(INPUT_GROUP_CSS_CLASS)).toBe(true);
5050

5151
const igxInputGroup = fixture.componentInstance.igxInputGroup;
52+
tick();
53+
fixture.detectChanges();
5254
// the default type should be line
5355
testInputGroupType('line', igxInputGroup, inputGroupElement);
54-
});
56+
}));
5557

56-
it('Initializes an input group with type box.', () => {
58+
it('Initializes an input group with type box.', fakeAsync(() => {
5759
const fixture = TestBed.createComponent(InputGroupBoxComponent);
5860
fixture.detectChanges();
5961

6062
const inputGroupElement = fixture.debugElement.query(By.css('igx-input-group')).nativeElement;
6163
expect(inputGroupElement.classList.contains(INPUT_GROUP_CSS_CLASS)).toBe(true);
6264

6365
const igxInputGroup = fixture.componentInstance.igxInputGroup;
66+
tick();
67+
fixture.detectChanges();
6468
testInputGroupType('box', igxInputGroup, inputGroupElement);
65-
});
69+
}));
6670

67-
it('Initializes an input group with type border.', () => {
71+
it('Initializes an input group with type border.', fakeAsync(() => {
6872
const fixture = TestBed.createComponent(InputGroupBorderComponent);
6973
fixture.detectChanges();
7074

7175
const inputGroupElement = fixture.debugElement.query(By.css('igx-input-group')).nativeElement;
7276
expect(inputGroupElement.classList.contains(INPUT_GROUP_CSS_CLASS)).toBe(true);
7377

7478
const igxInputGroup = fixture.componentInstance.igxInputGroup;
79+
tick();
80+
fixture.detectChanges();
7581
testInputGroupType('border', igxInputGroup, inputGroupElement);
76-
});
82+
}));
7783

78-
it('Initializes an input group with type search.', () => {
84+
it('Initializes an input group with type search.', fakeAsync(() => {
7985
const fixture = TestBed.createComponent(InputGroupSearchComponent);
8086
fixture.detectChanges();
8187

8288
const inputGroupElement = fixture.debugElement.query(By.css('igx-input-group')).nativeElement;
8389
expect(inputGroupElement.classList.contains(INPUT_GROUP_CSS_CLASS)).toBe(true);
8490

8591
const igxInputGroup = fixture.componentInstance.igxInputGroup;
92+
tick();
93+
fixture.detectChanges();
8694
testInputGroupType('search', igxInputGroup, inputGroupElement);
87-
});
95+
}));
8896

89-
it('Should respect type Token and be able to change input group type programmatically.', () => {
97+
it('Should respect type Token and be able to change input group type programmatically.', fakeAsync(() => {
9098
const fixture = TestBed.createComponent(InputGroupComponent);
9199
fixture.detectChanges();
92100

93101
const inputGroupElement = fixture.debugElement.query(By.css('igx-input-group')).nativeElement;
94102
const igxInputGroup = fixture.componentInstance.igxInputGroup;
95103

104+
tick();
105+
fixture.detectChanges();
106+
96107
// a Token is passed and can be obtained
97108
expect(fixture.componentInstance.IGTOKEN).toBe('box');
98109

@@ -120,7 +131,7 @@ describe('IgxInputGroup', () => {
120131
igxInputGroup.type = null;
121132
fixture.detectChanges();
122133
testInputGroupType('box', igxInputGroup, inputGroupElement);
123-
});
134+
}));
124135

125136
it('disabled input should properly detect changes.', () => {
126137
const fixture = TestBed.createComponent(InputGroupDisabledComponent);

projects/igniteui-angular/src/lib/input-group/input-group.component.ts

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { CommonModule, DOCUMENT } from '@angular/common';
22
import {
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';
1718
import { IgxHintDirective } from '../directives/hint/hint.directive';
1819
import {
@@ -36,6 +37,7 @@ import { IInputResourceStrings } from '../core/i18n/input-resources';
3637
import { CurrentResourceStrings } from '../core/i18n/resources';
3738

3839
import { mkenum, PlatformUtil } from '../core/utils';
40+
import { Subject, Subscription } from 'rxjs';
3941

4042
const 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 */

src/app/dialog/dialog.sample.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ <h4 class="sample-title">Templated Dialog</h4>
100100
<igx-dialog-title>Title</igx-dialog-title>
101101

102102
<div class="login-form">
103-
<igx-input-group>
103+
<igx-input-group theme="material" type="box">
104104
<igx-prefix>
105105
<igx-icon>person</igx-icon>
106106
</igx-prefix>
107107
<input type="text" igxInput />
108108
<label igxLabel>Username</label>
109109
</igx-input-group>
110-
<igx-input-group>
110+
<igx-input-group type="box">
111111
<igx-prefix>
112112
<igx-icon>lock</igx-icon>
113113
</igx-prefix>

0 commit comments

Comments
 (0)