Skip to content

Commit 0873e10

Browse files
authored
Merge branch '9.1.x' into ddincheva/monthPickerAnimation-9.1
2 parents bdd95e9 + 5aa3af7 commit 0873e10

File tree

12 files changed

+567
-105
lines changed

12 files changed

+567
-105
lines changed

projects/igniteui-angular/src/lib/badge/badge.component.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class IgxBadgeComponent {
8787
* ```
8888
*/
8989
@Input()
90-
public value = '';
90+
public value: string | number = '';
9191

9292
/**
9393
* Sets/gets an icon for the badge from the material icons set.
@@ -154,18 +154,13 @@ export class IgxBadgeComponent {
154154
* @internal
155155
*/
156156
get roleDescription() {
157-
let message: string;
158-
159157
// tslint:disable-next-line:prefer-conditional-expression
160158
if (this.icon) {
161-
message = this.type + ' type badge with icon type ' + this.icon;
162-
} else if (this.value) {
163-
message = this.type + ' badge type with value ' + this.value;
164-
} else {
165-
message = this.type + ' badge type without value';
159+
return this.type + ' type badge with icon type ' + this.icon;
160+
} else if (this.value || this.value === 0) {
161+
return this.type + ' badge type with value ' + this.value;
166162
}
167-
168-
return message;
163+
return this.type + ' badge type without value';
169164
}
170165

171166
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<ng-content select="igx-hint, [igxHint]"></ng-content>
1010
</ng-container>
1111
<input igxInput #comboInput name="comboInput" type="text" [value]="value" readonly [attr.placeholder]="placeholder"
12-
[disabled]="disabled" (blur)="onBlur()" (focus)="onFocus()"/>
12+
[disabled]="disabled" (blur)="onBlur()" />
1313
<ng-container ngProjectAs="igx-suffix">
1414
<ng-content select="igx-suffix"></ng-content>
1515
</ng-container>

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

Lines changed: 75 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { AfterViewInit, ChangeDetectorRef, Component, Injectable, OnInit, ViewChild, OnDestroy, DebugElement } from '@angular/core';
2-
import { async, TestBed, tick, fakeAsync } from '@angular/core/testing';
2+
import { async, TestBed, tick, fakeAsync, ComponentFixture } from '@angular/core/testing';
33
import { By } from '@angular/platform-browser';
44
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
5-
import { FormGroup, FormControl, Validators, FormBuilder, ReactiveFormsModule, FormsModule, NgControl } from '@angular/forms';
5+
import { FormGroup, FormControl, Validators, FormBuilder, ReactiveFormsModule, FormsModule, NgControl, NgModel } from '@angular/forms';
66
import { IgxComboComponent, IgxComboModule, IComboSelectionChangeEventArgs, IgxComboState,
77
IComboSearchInputEventArgs } from './combo.component';
88
import { IgxComboItemComponent } from './combo-item.component';
@@ -60,7 +60,7 @@ const defaultDropdownItemHeight = 40;
6060
const defaultDropdownItemMaxHeight = 400;
6161

6262
describe('igxCombo', () => {
63-
let fixture;
63+
let fixture: ComponentFixture<any>;
6464
let combo: IgxComboComponent;
6565
let input: DebugElement;
6666

@@ -94,12 +94,10 @@ describe('igxCombo', () => {
9494

9595
// writeValue
9696
expect(combo.value).toBe('');
97-
mockSelection.add_items.and.returnValue(new Set(['test']));
97+
mockSelection.get.and.returnValue(new Set(['test']));
9898
spyOnProperty(combo, 'isRemote').and.returnValue(false);
9999
combo.writeValue(['test']);
100-
// TODO: Uncomment after fix for write value going through entire selection process
101-
// expect(mockNgControl.registerOnChangeCb).not.toHaveBeenCalled();
102-
expect(mockSelection.add_items).toHaveBeenCalledWith(combo.id, ['test'], true);
100+
expect(mockNgControl.registerOnChangeCb).not.toHaveBeenCalled();
103101
expect(mockSelection.select_items).toHaveBeenCalledWith(combo.id, ['test'], true);
104102
expect(combo.value).toBe('test');
105103

@@ -120,11 +118,8 @@ describe('igxCombo', () => {
120118
spyOnProperty(combo, 'collapsed').and.returnValue(true);
121119
spyOnProperty(combo, 'valid', 'set');
122120

123-
combo.onFocus();
124-
expect(mockNgControl.registerOnTouchedCb).toHaveBeenCalledTimes(1);
125-
126121
combo.onBlur();
127-
expect(mockNgControl.registerOnTouchedCb).toHaveBeenCalledTimes(2);
122+
expect(mockNgControl.registerOnTouchedCb).toHaveBeenCalledTimes(1);
128123
});
129124
it('should correctly handle ngControl validity', () => {
130125
pending('Convert existing form test here');
@@ -199,17 +194,18 @@ describe('igxCombo', () => {
199194
combo = new IgxComboComponent({ nativeElement: null }, mockCdr, mockSelection as any, mockComboService, null, mockInjector);
200195
combo.ngOnInit();
201196
combo.data = data;
202-
spyOn(combo, 'selectItems');
197+
mockSelection.select_items.calls.reset();
198+
spyOnProperty(combo, 'isRemote').and.returnValue(false);
203199
combo.writeValue(['EXAMPLE']);
204-
expect(combo.selectItems).toHaveBeenCalledTimes(1);
200+
expect(mockSelection.select_items).toHaveBeenCalledTimes(1);
205201

206-
// Calling "SelectItems" through the writeValue accessor should clear the previous values;
202+
// Calling "select_items" through the writeValue accessor should clear the previous values;
207203
// Select items is called with the invalid value and it is written in selection, though no item is selected
208204
// Controlling the selection is up to the user
209-
expect(combo.selectItems).toHaveBeenCalledWith(['EXAMPLE'], true);
205+
expect(mockSelection.select_items).toHaveBeenCalledWith(combo.id, ['EXAMPLE'], true);
210206
combo.writeValue(combo.data[0]);
211207
// When value key is specified, the item's value key is stored in the selection
212-
expect(combo.selectItems).toHaveBeenCalledWith(combo.data[0], true);
208+
expect(mockSelection.select_items).toHaveBeenCalledWith(combo.id, [], true);
213209
});
214210
it('should select items through setSelctedItem method', () => {
215211
const selectionService = new IgxSelectionAPIService();
@@ -2578,6 +2574,7 @@ describe('igxCombo', () => {
25782574
expect(combo.valid).toEqual(IgxComboState.INVALID);
25792575
expect(combo.comboInput.valid).toEqual(IgxInputState.INVALID);
25802576

2577+
input.triggerEventHandler('focus', {});
25812578
combo.selectAllItems();
25822579
fixture.detectChanges();
25832580
expect(combo.valid).toEqual(IgxComboState.VALID);
@@ -2589,17 +2586,72 @@ describe('igxCombo', () => {
25892586
expect(combo.valid).toEqual(IgxComboState.INVALID);
25902587
expect(combo.comboInput.valid).toEqual(IgxInputState.INVALID);
25912588
});
2592-
it('should have correctly bound focus and blur handlers', () => {
2593-
spyOn(combo, 'onFocus');
2594-
spyOn(combo, 'onBlur');
2589+
it('should properly init with empty array and handle consecutive model changes', fakeAsync(() => {
2590+
const model = fixture.debugElement.query(By.directive(NgModel)).injector.get(NgModel);
2591+
fixture.componentInstance.values = [];
2592+
fixture.detectChanges();
2593+
tick();
2594+
expect(combo.valid).toEqual(IgxComboState.INITIAL);
2595+
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);
2596+
expect(model.valid).toBeFalse();
2597+
expect(model.dirty).toBeFalse();
2598+
expect(model.touched).toBeFalse();
25952599

2596-
input.triggerEventHandler('focus', {});
2597-
expect(combo.onFocus).toHaveBeenCalled();
2598-
expect(combo.onFocus).toHaveBeenCalledWith();
2600+
fixture.componentInstance.values = ['Missouri'];
2601+
fixture.detectChanges();
2602+
tick();
2603+
expect(combo.valid).toEqual(IgxComboState.INITIAL);
2604+
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);
2605+
expect(combo.selectedItems()).toEqual(['Missouri']);
2606+
expect(combo.value).toEqual('Missouri');
2607+
expect(model.valid).toBeTrue();
2608+
expect(model.touched).toBeFalse();
2609+
2610+
fixture.componentInstance.values = ['Missouri', 'Missouri'];
2611+
fixture.detectChanges();
2612+
expect(combo.valid).toEqual(IgxComboState.INITIAL);
2613+
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);
2614+
expect(combo.selectedItems()).toEqual(['Missouri']);
2615+
expect(combo.value).toEqual('Missouri');
2616+
expect(model.valid).toBeTrue();
2617+
expect(model.touched).toBeFalse();
2618+
2619+
fixture.componentInstance.values = null;
2620+
fixture.detectChanges();
2621+
tick();
2622+
expect(combo.valid).toEqual(IgxComboState.INITIAL);
2623+
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);
2624+
expect(combo.selectedItems()).toEqual([]);
2625+
expect(combo.value).toEqual('');
2626+
expect(model.valid).toBeFalse();
2627+
expect(model.touched).toBeFalse();
2628+
expect(model.dirty).toBeFalse();
2629+
2630+
combo.onBlur();
2631+
fixture.detectChanges();
2632+
expect(combo.valid).toEqual(IgxComboState.INVALID);
2633+
expect(combo.comboInput.valid).toEqual(IgxInputState.INVALID);
2634+
expect(model.valid).toBeFalse();
2635+
expect(model.touched).toBeTrue();
2636+
expect(model.dirty).toBeFalse();
2637+
2638+
fixture.componentInstance.values = ['New Jersey'];
2639+
fixture.detectChanges();
2640+
tick();
2641+
expect(combo.valid).toEqual(IgxComboState.INITIAL);
2642+
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);
2643+
expect(combo.selectedItems()).toEqual(['New Jersey']);
2644+
expect(combo.value).toEqual('New Jersey');
2645+
expect(model.valid).toBeTrue();
2646+
expect(model.touched).toBeTrue();
2647+
expect(model.dirty).toBeFalse();
2648+
}));
2649+
it('should have correctly bound blur handler', () => {
2650+
spyOn(combo, 'onBlur');
25992651

26002652
input.triggerEventHandler('blur', {});
26012653
expect(combo.onBlur).toHaveBeenCalled();
2602-
expect(combo.onFocus).toHaveBeenCalledWith();
2654+
expect(combo.onBlur).toHaveBeenCalledWith();
26032655
});
26042656
});
26052657
});

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,11 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
11451145
protected onStatusChanged = () => {
11461146
if ((this.ngControl.control.touched || this.ngControl.control.dirty) &&
11471147
(this.ngControl.control.validator || this.ngControl.control.asyncValidator)) {
1148-
this.valid = this.ngControl.valid ? IgxComboState.VALID : IgxComboState.INVALID;
1148+
if (!this.collapsed || this.inputGroup.isFocused) {
1149+
this.valid = this.ngControl.valid ? IgxComboState.VALID : IgxComboState.INVALID;
1150+
} else {
1151+
this.valid = this.ngControl.valid ? IgxComboState.INITIAL : IgxComboState.INVALID;
1152+
}
11491153
}
11501154
this.manageRequiredAsterisk();
11511155
}
@@ -1172,13 +1176,6 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
11721176
}
11731177
}
11741178

1175-
/** @hidden @internal */
1176-
public onFocus() {
1177-
if (this.collapsed) {
1178-
this._onTouchedCallback();
1179-
}
1180-
}
1181-
11821179
/**
11831180
* @hidden @internal
11841181
*/
@@ -1218,8 +1215,10 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
12181215
* @hidden @internal
12191216
*/
12201217
public writeValue(value: any[]): void {
1221-
this.selectItems(value, true);
1222-
this.cdr.markForCheck();
1218+
const selection = Array.isArray(value) ? value : [];
1219+
const oldSelection = this.selectedItems();
1220+
this.selection.select_items(this.id, selection, true);
1221+
this._value = this.createDisplayText(this.selectedItems(), oldSelection);
12231222
}
12241223

12251224
/**

projects/igniteui-angular/src/lib/grids/cell.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,11 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
778778
* @internal
779779
*/
780780
pointerenter = (event: PointerEvent) => {
781+
const isHierarchicalGrid = this.grid.nativeElement.tagName.toLowerCase() === 'igx-hierarchical-grid';
782+
if (!this.grid.navigation.activeNode ||
783+
(isHierarchicalGrid && (!this.grid.navigation.activeNode.gridID || this.grid.navigation.activeNode.gridID !== this.gridID))) {
784+
return;
785+
}
781786
const dragMode = this.selectionService.pointerEnter(this.selectionNode, event);
782787
if (dragMode) {
783788
this.grid.cdr.detectChanges();
@@ -789,7 +794,9 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
789794
* @internal
790795
*/
791796
pointerup = (event: PointerEvent) => {
792-
if (!isLeftClick(event)) { return; }
797+
const isHierarchicalGrid = this.grid.nativeElement.tagName.toLowerCase() === 'igx-hierarchical-grid';
798+
if (!isLeftClick(event) || !this.grid.navigation.activeNode || (isHierarchicalGrid && (!this.grid.navigation.activeNode.gridID ||
799+
this.grid.navigation.activeNode.gridID !== this.gridID))) { return; }
793800
if (this.selectionService.pointerUp(this.selectionNode, this.grid.onRangeSelection)) {
794801
this.grid.cdr.detectChanges();
795802
}

0 commit comments

Comments
 (0)