Skip to content

Commit 9a9f3e5

Browse files
authored
Merge branch '9.1.x' into skrastev/fix-7561-9.1.x
2 parents 6a824f6 + 5290728 commit 9a9f3e5

File tree

7 files changed

+64
-20
lines changed

7 files changed

+64
-20
lines changed

projects/igniteui-angular/src/lib/date-range-picker/date-range-picker-inputs.common.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ export class IgxDateRangeInputsBaseComponent extends IgxInputGroupComponent {
7777
public updateInputValidity(state: IgxInputState) {
7878
this.inputDirective.valid = state;
7979
}
80-
8180
}
8281

8382
/**

projects/igniteui-angular/src/lib/date-range-picker/date-range-picker.component.spec.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ describe('IgxDateRangePicker', () => {
491491
TestBed.configureTestingModule({
492492
declarations: [
493493
DateRangeTestComponent,
494-
DateRangeTwoInputsTestComponent
494+
DateRangeTwoInputsTestComponent,
495+
DateRangeTwoInputsNgModelTestComponent
495496
],
496497
imports: [IgxDateRangePickerModule, IgxDateTimeEditorModule, IgxInputGroupModule, FormsModule, NoopAnimationsModule]
497498
})
@@ -584,6 +585,7 @@ describe('IgxDateRangePicker', () => {
584585
verifyDateRange();
585586
});
586587
});
588+
587589
describe('Keyboard navigation', () => {
588590
it('should toggle the calendar with ALT + DOWN/UP ARROW key', fakeAsync(() => {
589591
expect(dateRange.collapsed).toBeTruthy();
@@ -630,6 +632,19 @@ describe('IgxDateRangePicker', () => {
630632
expect(dateRange.onClosed.emit).toHaveBeenCalledTimes(1);
631633
}));
632634
});
635+
636+
describe('Data binding', () => {
637+
it('should properly update component value with ngModel bound to projected inputs - #7353', fakeAsync(() => {
638+
fixture = TestBed.createComponent(DateRangeTwoInputsNgModelTestComponent);
639+
fixture.detectChanges();
640+
const range = (fixture.componentInstance as DateRangeTwoInputsNgModelTestComponent).range;
641+
fixture.componentInstance.dateRange.open();
642+
fixture.detectChanges();
643+
tick();
644+
expect(fixture.componentInstance.dateRange.value.start.getTime()).toEqual(range.start.getTime());
645+
expect(fixture.componentInstance.dateRange.value.end.getTime()).toEqual(range.end.getTime());
646+
}));
647+
});
633648
});
634649

635650
describe('Calendar UI', () => {
@@ -821,6 +836,22 @@ export class DateRangeTwoInputsTestComponent extends DateRangeTestComponent {
821836
range;
822837
}
823838

839+
@Component({
840+
selector: 'igx-date-range-two-inputs-ng-model',
841+
template: `
842+
<igx-date-range-picker [mode]="'dropdown'">
843+
<igx-date-range-start>
844+
<input igxInput [(ngModel)]="range.start" igxDateTimeEditor>
845+
</igx-date-range-start>
846+
<igx-date-range-end>
847+
<input igxInput [(ngModel)]="range.end" igxDateTimeEditor>
848+
</igx-date-range-end>
849+
</igx-date-range-picker>`
850+
})
851+
export class DateRangeTwoInputsNgModelTestComponent extends DateRangeTestComponent {
852+
public range = { start: new Date(2020, 1, 1), end: new Date(2020, 1, 4) };
853+
}
854+
824855
@Component({
825856
selector: 'igx-date-range-single-input-label-test',
826857
template: `

projects/igniteui-angular/src/lib/date-range-picker/date-range-picker.component.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ import {
5252
IgxPickerToggleComponent
5353
} from './date-range-picker-inputs.common';
5454

55-
56-
5755
/**
5856
* Provides the ability to select a range of dates from a calendar UI or editable inputs.
5957
*
@@ -638,8 +636,13 @@ export class IgxDateRangePickerComponent extends DisplayDensityBase
638636
if (this._ngControl) {
639637
this._statusChanges$ = this._ngControl.statusChanges.subscribe(this.onStatusChanged.bind(this));
640638
}
641-
this.initialSetValue();
642-
this.updateInputs();
639+
640+
// delay the invocation of initialSetValue
641+
// until the current change detection cycle has completed
642+
Promise.resolve().then(() => {
643+
this.initialSetValue();
644+
this.updateInputs();
645+
});
643646
}
644647

645648
/** @hidden @internal */
@@ -915,13 +918,15 @@ export class IgxDateRangePickerComponent extends DisplayDensityBase
915918
}
916919

917920
private initialSetValue() {
918-
// if there is no value, no ngControl but we have inputs we may have value set trough
919-
// inputs' ngModels - we should generate our initial control value
920-
if (!this.value && this.hasProjectedInputs && !this._ngControl) {
921-
const start = this.projectedInputs.find(i => i instanceof IgxDateRangeStartComponent).dateTimeEditor.value;
922-
const end = this.projectedInputs.find(i => i instanceof IgxDateRangeEndComponent).dateTimeEditor.value;
923-
this.updateValue({ start, end });
924-
921+
// if there is no value and no ngControl on the picker but we have inputs we may have value set through
922+
// their ngModels - we should generate our initial control value
923+
if ((!this.value || (!this.value.start && !this.value.end)) && this.hasProjectedInputs && !this._ngControl) {
924+
const start = this.projectedInputs.find(i => i instanceof IgxDateRangeStartComponent);
925+
const end = this.projectedInputs.find(i => i instanceof IgxDateRangeEndComponent);
926+
this._value = {
927+
start: start.dateTimeEditor.value,
928+
end: end.dateTimeEditor.value
929+
};
925930
}
926931
}
927932

projects/igniteui-angular/src/lib/directives/date-time-editor/date-time-editor.directive.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {
22
Directive, Input, ElementRef,
3-
Renderer2, NgModule, Output, EventEmitter, Inject, LOCALE_ID, OnChanges, SimpleChanges, Host, Optional, Injector
3+
Renderer2, NgModule, Output, EventEmitter, Inject, LOCALE_ID, OnChanges, SimpleChanges
44
} from '@angular/core';
55
import {
66
ControlValueAccessor,
7-
Validator, AbstractControl, ValidationErrors, NG_VALIDATORS, NgControl, NG_VALUE_ACCESSOR,
7+
Validator, AbstractControl, ValidationErrors, NG_VALIDATORS, NG_VALUE_ACCESSOR,
88
} from '@angular/forms';
99
import { formatDate, DOCUMENT } from '@angular/common';
1010
import { IgxMaskDirective } from '../mask/mask.directive';
@@ -569,8 +569,8 @@ export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnCh
569569
return date && date.getTime && !isNaN(date.getTime());
570570
}
571571

572-
// TODO: move parseDate to utils
573-
public parseDate(val: string): Date | null {
572+
// TODO: move parseDate to utils
573+
public parseDate(val: string): Date | null {
574574
if (!val) { return null; }
575575
return DatePickerUtil.parseValueFromMask(val, this._inputDateParts, this.promptChar);
576576
}

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,13 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
599599
*/
600600
public rowDragging = false;
601601

602+
/**
603+
* Gets the row ID that is being dragged.
604+
* @remarks
605+
* The row ID is either the primaryKey value or the data record instance.
606+
*/
607+
public dragRowID = null;
608+
602609

603610
/**
604611
* Gets/Sets whether the rows are editable.

projects/igniteui-angular/src/lib/grids/row-drag.directive.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class IgxRowDragDirective extends IgxDragDirective implements OnDestroy {
6060
this._clicked = false;
6161
return;
6262
}
63-
this.row.dragging = true;
63+
this.row.grid.dragRowID = this.row.rowID;
6464
this.row.grid.rowDragging = true;
6565
this.row.grid.markForCheck();
6666

@@ -143,7 +143,7 @@ export class IgxRowDragDirective extends IgxDragDirective implements OnDestroy {
143143

144144
private endDragging() {
145145
this.onTransitionEnd(null);
146-
this.row.dragging = false;
146+
this.row.grid.dragRowID = null;
147147
this.row.grid.rowDragging = false;
148148
this.row.grid.markForCheck();
149149
this._unsubscribe();

projects/igniteui-angular/src/lib/grids/row.directive.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ export class IgxRowDirective<T extends IgxGridBaseDirective & GridType> implemen
248248
/**
249249
* @hidden
250250
*/
251-
public dragging = false;
251+
public get dragging() {
252+
return this.grid.dragRowID === this.rowID;
253+
}
252254

253255
// TODO: Refactor
254256
public get inEditMode(): boolean {

0 commit comments

Comments
 (0)