Skip to content

Commit 2ff3d3b

Browse files
authored
Merge branch '14.1.x' into mkirova/improve-validator-aria
2 parents e13a1e3 + 320dc6c commit 2ff3d3b

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed

projects/igniteui-angular/src/lib/combo/combo.common.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,13 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
980980
});
981981
}
982982

983+
/** @hidden @internal */
984+
public ngDoCheck() {
985+
if (this.data?.length && this.selection.length) {
986+
this._value = this.createDisplayText(this.selection, []);
987+
}
988+
}
989+
983990
/** @hidden @internal */
984991
public ngOnDestroy() {
985992
this.destroy$.next();

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

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,8 @@ describe('igxCombo', () => {
18981898
TestBed.configureTestingModule({
18991899
declarations: [
19001900
IgxComboSampleComponent,
1901-
IgxComboRemoteDataComponent
1901+
IgxComboRemoteDataComponent,
1902+
IgxComboBindingDataAfterInitComponent
19021903
],
19031904
imports: [
19041905
IgxComboModule,
@@ -2187,6 +2188,16 @@ describe('igxCombo', () => {
21872188
expect(combo.selection.length).toEqual(0);
21882189
expect((combo as any)._remoteSelection[0]).toBeUndefined();
21892190
});
2191+
it('should add predefined selection to the input when data is bound after initialization', fakeAsync(() => {
2192+
fixture = TestBed.createComponent(IgxComboBindingDataAfterInitComponent);
2193+
fixture.detectChanges();
2194+
input = fixture.debugElement.query(By.css(`.${CSS_CLASS_COMBO_INPUTGROUP}`));
2195+
tick(1200);
2196+
fixture.detectChanges();
2197+
2198+
const expectedOutput = 'One';
2199+
expect(input.nativeElement.value).toEqual(expectedOutput);
2200+
}));
21902201
});
21912202
describe('Grouping tests: ', () => {
21922203
configureTestSuite();
@@ -3311,6 +3322,29 @@ class="input-container" [filterable]="true" placeholder="Location(s)"
33113322
`
33123323
})
33133324

3325+
@Component({
3326+
template: `
3327+
<form [formGroup]="reactiveForm" (ngSubmit)="onSubmitReactive()">
3328+
<p>
3329+
<label>First Name:</label>
3330+
<input type="text" formControlName="firstName">
3331+
</p>
3332+
<p>
3333+
<label>Password:</label>
3334+
<input type="password" formControlName="password">
3335+
</p>
3336+
<p>
3337+
<igx-combo #comboReactive formControlName="townCombo"
3338+
class="input-container" [filterable]="true" placeholder="Location(s)"
3339+
[data]="items" [displayKey]="'field'" [groupKey]="'region'"><label igxLabel>Town</label></igx-combo>
3340+
</p>
3341+
<p>
3342+
<button type="submit" [disabled]="!reactiveForm.valid">Submit</button>
3343+
</p>
3344+
</form>
3345+
`
3346+
})
3347+
33143348
class IgxComboFormComponent {
33153349
@ViewChild('comboReactive', { read: IgxComboComponent, static: true })
33163350
public combo: IgxComboComponent;
@@ -3583,3 +3617,22 @@ export class ComboModelBindingComponent implements OnInit {
35833617
{ text: 'Four', id: 3 }, { text: 'Five', id: 4 }];
35843618
}
35853619
}
3620+
3621+
@Component({
3622+
template: `
3623+
<igx-combo [(ngModel)]="selectedItems" [data]="items" [valueKey]="'id'" [displayKey]="'text'"></igx-combo>`
3624+
})
3625+
export class IgxComboBindingDataAfterInitComponent implements AfterViewInit {
3626+
public items: any[] = [];
3627+
public selectedItems: any[] = [0];
3628+
3629+
constructor(private cdr: ChangeDetectorRef) { }
3630+
3631+
public ngAfterViewInit() {
3632+
setTimeout(() => {
3633+
this.items = [{ text: 'One', id: 0 }, { text: 'Two', id: 1 }, { text: 'Three', id: 2 },
3634+
{ text: 'Four', id: 3 }, { text: 'Five', id: 4 }];
3635+
this.cdr.detectChanges();
3636+
}, 1000);
3637+
}
3638+
}

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,8 @@ describe('IgxSimpleCombo', () => {
13241324
beforeAll(waitForAsync(() => {
13251325
TestBed.configureTestingModule({
13261326
declarations: [
1327-
IgxComboRemoteDataComponent
1327+
IgxComboRemoteDataComponent,
1328+
IgxSimpleComboBindingDataAfterInitComponent
13281329
],
13291330
imports: [
13301331
IgxSimpleComboModule,
@@ -1352,6 +1353,17 @@ describe('IgxSimpleCombo', () => {
13521353
expect(combo.selection.length).toEqual(0);
13531354
expect((combo as any)._remoteSelection[0]).toBeUndefined();
13541355
});
1356+
it('should add predefined selection to the input when data is bound after initialization', fakeAsync(() => {
1357+
fixture = TestBed.createComponent(IgxSimpleComboBindingDataAfterInitComponent);
1358+
fixture.detectChanges();
1359+
combo = fixture.componentInstance.instance;
1360+
input = fixture.debugElement.query(By.css(`.${CSS_CLASS_COMBO_INPUTGROUP}`));
1361+
tick(1200);
1362+
fixture.detectChanges();
1363+
1364+
const expectedOutput = 'One';
1365+
expect(input.nativeElement.value).toEqual(expectedOutput);
1366+
}));
13551367
});
13561368
});
13571369

@@ -1559,3 +1571,22 @@ class IgxSimpleComboInTemplatedFormComponent {
15591571
}
15601572
}
15611573
}
1574+
1575+
@Component({
1576+
template: `
1577+
<igx-simple-combo [(ngModel)]="selectedItem" [data]="items" [valueKey]="'id'" [displayKey]="'text'"></igx-simple-combo>`
1578+
})
1579+
export class IgxSimpleComboBindingDataAfterInitComponent implements AfterViewInit {
1580+
public items: any[];
1581+
public selectedItem: number = 1;
1582+
1583+
constructor(private cdr: ChangeDetectorRef) { }
1584+
1585+
public ngAfterViewInit() {
1586+
setTimeout(() => {
1587+
this.items = [{ text: 'One', id: 1 }, { text: 'Two', id: 2 }, { text: 'Three', id: 3 },
1588+
{ text: 'Four', id: 4 }, { text: 'Five', id: 5 }];
1589+
this.cdr.detectChanges();
1590+
}, 1000);
1591+
}
1592+
}

0 commit comments

Comments
 (0)