Skip to content

Commit f9e7761

Browse files
Merge branch '17.2.x' of https://github.com/IgniteUI/igniteui-angular into ganastasov/fix-14187-17.2.x
2 parents b6a730f + 257e9c1 commit f9e7761

File tree

22 files changed

+498
-153
lines changed

22 files changed

+498
-153
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ All notable changes for each version of this project will be documented in this
2828
### General
2929
- `IgxSimpleCombo`
3030
- **Behavioral Change** When bound to `ngModel` and `formControlName` directives, the model would not be updated when the user types into the input and will only be updated on selection.
31+
- **Behavioral Change** The `selectionChanging` event will now trigger when typing the first character in the input if there is a previously selected value in the `IgxSimpleCombo`.
3132

3233

3334
## 17.1.0

projects/igniteui-angular/src/lib/calendar/month-picker/month-picker.component.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,35 @@ describe('IgxMonthPicker', () => {
525525
expect(monthPicker.activeViewChanged.emit).toHaveBeenCalled();
526526
expect(monthPicker.activeView).toEqual('year');
527527
});
528+
529+
it('should emit viewDateChanged event when changing year with arrow buttons', () => {
530+
const fixture = TestBed.createComponent(IgxMonthPickerSampleComponent);
531+
const monthPicker = fixture.componentInstance.monthPicker;
532+
spyOn(monthPicker.viewDateChanged, 'emit');
533+
534+
fixture.detectChanges();
535+
536+
const dom = fixture.debugElement;
537+
const prev = dom.query(By.css('.igx-calendar-picker__prev'));
538+
const next = dom.query(By.css('.igx-calendar-picker__next'));
539+
540+
UIInteractions.simulateMouseDownEvent(prev.nativeElement);
541+
fixture.detectChanges();
542+
543+
expect(monthPicker.viewDateChanged.emit).toHaveBeenCalledWith({
544+
previousValue: new Date(2019, 1, 1),
545+
currentValue: new Date(2018, 1, 1)
546+
});
547+
548+
UIInteractions.simulateMouseDownEvent(next.nativeElement);
549+
UIInteractions.simulateMouseDownEvent(next.nativeElement);
550+
fixture.detectChanges();
551+
552+
expect(monthPicker.viewDateChanged.emit).toHaveBeenCalledWith({
553+
previousValue: new Date(2018, 1, 1),
554+
currentValue: new Date(2019, 1, 1)
555+
});
556+
});
528557
});
529558

530559
@Component({

projects/igniteui-angular/src/lib/calendar/month-picker/month-picker.component.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ export class IgxMonthPickerComponent extends IgxCalendarBaseDirective implements
117117
if (this.isDecadeView) {
118118
this.viewDate = CalendarDay.from(this.viewDate).add('year', -15).native;
119119
}
120+
121+
this.viewDateChanged.emit({
122+
previousValue: this.previousViewDate,
123+
currentValue: this.viewDate,
124+
});
120125
}
121126

122127
/**
@@ -134,6 +139,11 @@ export class IgxMonthPickerComponent extends IgxCalendarBaseDirective implements
134139
if (this.isDecadeView) {
135140
this.viewDate = CalendarDay.from(this.viewDate).add('year', 15).native;
136141
}
142+
143+
this.viewDateChanged.emit({
144+
previousValue: this.previousViewDate,
145+
currentValue: this.viewDate,
146+
});
137147
}
138148

139149
/**

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { noop, Subject } from 'rxjs';
3030
import { takeUntil } from 'rxjs/operators';
3131
import { DisplayDensityBase, DisplayDensityToken, IDisplayDensityOptions } from '../core/density';
3232
import { IgxSelectionAPIService } from '../core/selection';
33-
import { CancelableBrowserEventArgs, cloneArray, IBaseCancelableBrowserEventArgs, IBaseEventArgs, isNaNvalue, rem } from '../core/utils';
33+
import { CancelableBrowserEventArgs, cloneArray, IBaseCancelableBrowserEventArgs, IBaseEventArgs, rem } from '../core/utils';
3434
import { SortingDirection } from '../data-operations/sorting-strategy';
3535
import { IForOfState, IgxForOfDirective } from '../directives/for-of/for_of.directive';
3636
import { IgxIconService } from '../icon/icon.service';
@@ -46,6 +46,7 @@ import {
4646
import { IComboItemAdditionEvent, IComboSearchInputEventArgs } from './public_api';
4747
import { ComboResourceStringsEN, IComboResourceStrings } from '../core/i18n/combo-resources';
4848
import { getCurrentResourceStrings } from '../core/i18n/resources';
49+
import { isEqual } from 'lodash-es';
4950

5051
export const IGX_COMBO_COMPONENT = /*@__PURE__*/new InjectionToken<IgxComboBase>('IgxComboComponentToken');
5152

@@ -1282,9 +1283,7 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
12821283
}
12831284

12841285
return keys.map(key => {
1285-
const item = isNaNvalue(key)
1286-
? this.data.find(entry => isNaNvalue(entry[this.valueKey]))
1287-
: this.data.find(entry => entry[this.valueKey] === key);
1286+
const item = this.data.find(entry => isEqual(entry[this.valueKey], key));
12881287

12891288
return item !== undefined ? item : { [this.valueKey]: key };
12901289
});

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,6 +2342,55 @@ describe('igxCombo', () => {
23422342
expect(combo.value).toEqual([]);
23432343
expect(combo.displayValue).toEqual('Selected Count: 0');
23442344
});
2345+
it('should handle selection for combo with array type value key correctly - issue #14103', () => {
2346+
fixture = TestBed.createComponent(ComboArrayTypeValueKeyComponent);
2347+
fixture.detectChanges();
2348+
combo = fixture.componentInstance.combo;
2349+
input = fixture.debugElement.query(By.css(`.${CSS_CLASS_COMBO_INPUTGROUP}`));
2350+
const items = fixture.componentInstance.items;
2351+
expect(combo).toBeDefined();
2352+
2353+
const selectionSpy = spyOn(combo.selectionChanging, 'emit');
2354+
let expectedResults: IComboSelectionChangingEventArgs = {
2355+
newValue: [combo.data[1][combo.valueKey]],
2356+
oldValue: [],
2357+
newSelection: [combo.data[1]],
2358+
oldSelection: [],
2359+
added: [combo.data[1]],
2360+
removed: [],
2361+
event: undefined,
2362+
owner: combo,
2363+
displayText: `${combo.data[1][combo.displayKey]}`,
2364+
cancel: false
2365+
};
2366+
2367+
let expectedDisplayText = items[1][combo.displayKey];
2368+
combo.select([fixture.componentInstance.items[1].value]);
2369+
fixture.detectChanges();
2370+
2371+
expect(selectionSpy).toHaveBeenCalledWith(expectedResults);
2372+
expect(input.nativeElement.value).toEqual(expectedDisplayText);
2373+
2374+
expectedDisplayText = `${items[1][combo.displayKey]}, ${items[2][combo.displayKey]}`;
2375+
expectedResults = {
2376+
newValue: [combo.data[1][combo.valueKey], combo.data[2][combo.valueKey]],
2377+
oldValue: [combo.data[1][combo.valueKey]],
2378+
newSelection: [combo.data[1], combo.data[2]],
2379+
oldSelection: [combo.data[1]],
2380+
added: [combo.data[2]],
2381+
removed: [],
2382+
event: undefined,
2383+
owner: combo,
2384+
displayText: expectedDisplayText,
2385+
cancel: false
2386+
};
2387+
2388+
combo.select([items[2].value]);
2389+
fixture.detectChanges();
2390+
2391+
expect(selectionSpy).toHaveBeenCalledWith(expectedResults);
2392+
expect(input.nativeElement.value).toEqual(expectedDisplayText);
2393+
});
23452394
});
23462395
describe('Grouping tests: ', () => {
23472396
beforeEach(() => {
@@ -3797,3 +3846,32 @@ export class IgxComboBindingDataAfterInitComponent implements AfterViewInit {
37973846
}, 1000);
37983847
}
37993848
}
3849+
3850+
@Component({
3851+
template: `
3852+
<igx-combo [data]="items" valueKey="value" displayKey="item"></igx-combo>`,
3853+
standalone: true,
3854+
imports: [IgxComboComponent]
3855+
})
3856+
export class ComboArrayTypeValueKeyComponent {
3857+
@ViewChild(IgxComboComponent, { read: IgxComboComponent, static: true })
3858+
public combo: IgxComboComponent;
3859+
public items: any[] = [];
3860+
3861+
constructor() {
3862+
this.items = [
3863+
{
3864+
item: "Item1",
3865+
value: [1, 2, 3]
3866+
},
3867+
{
3868+
item: "Item2",
3869+
value: [4, 5, 6]
3870+
},
3871+
{
3872+
item: "Item3",
3873+
value: [7, 8, 9]
3874+
}
3875+
];
3876+
}
3877+
}

projects/igniteui-angular/src/lib/core/density.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ export class DisplayDensityBase implements DoCheck, OnInit {
193193

194194
/**
195195
* Sets the `--component-size` CSS variable based on the value of Display Density
196+
* @hidden @internal
196197
*/
197198
public getComponentSizeStyles() {
198199
switch (this._displayDensity || this.oldDisplayDensityOptions.displayDensity) {

projects/igniteui-angular/src/lib/core/utils.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,6 @@ export const isEqual = (obj1, obj2): boolean => {
226226
return obj1 === obj2;
227227
};
228228

229-
/**
230-
* Checks if provided variable is the value NaN
231-
*
232-
* @param value Value to check
233-
* @returns true if provided variable is NaN
234-
* @hidden
235-
*/
236-
export const isNaNvalue = (value: any): boolean => isNaN(value) && value !== undefined && typeof value !== 'string';
237-
238229
/**
239230
* Utility service taking care of various utility functions such as
240231
* detecting browser features, general cross browser DOM manipulation, etc.

projects/igniteui-angular/src/lib/directives/for-of/for_of.directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,7 @@ export class IgxGridForOfDirective<T, U extends T[] = T[]> extends IgxForOfDirec
16211621
}
16221622
if (this.igxForScrollOrientation === 'horizontal') {
16231623
// in case collection has changes, reset sync service
1624-
this.syncService.setMaster(this, true);
1624+
this.syncService.setMaster(this, this.igxGridForOfUniqueSizeCache);
16251625
}
16261626
}
16271627
const defaultItemSize = 'igxForItemSize';

projects/igniteui-angular/src/lib/directives/for-of/for_of.sync.service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export class IgxForOfSyncService {
2121
*/
2222
public setMaster(directive: IgxGridForOfDirective<any, any[]>, forced = false) {
2323
const orientation = directive.igxForScrollOrientation;
24+
// in case master is not in dom, set a new master
25+
const isMasterInDom = this._master.get(orientation)?.dc?.instance?._viewContainer.element.nativeElement.isConnected;
26+
if (!isMasterInDom) {
27+
forced = true;
28+
}
2429
if (orientation && (forced || !this._master.has(orientation))) {
2530
this._master.set(orientation, directive);
2631
}

0 commit comments

Comments
 (0)