Skip to content

Commit c0858a8

Browse files
committed
feat(drp): typing a single value results in calendar range of single date
1 parent cc7b014 commit c0858a8

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,8 @@ describe('IgxDateRangePicker', () => {
11291129
expect(endInput.nativeElement.value).toEqual(inputEndDate);
11301130
});
11311131

1132-
it('should select a range from the calendar only when the two inputs are filled in', fakeAsync(() => {
1132+
it('should select a range from the calendar only when any of the two inputs are filled in', fakeAsync(() => {
1133+
// refactored to any of the two inputs, instead of both, to match the behavior in WC - #16131
11331134
startInput.triggerEventHandler('focus', {});
11341135
fixture.detectChanges();
11351136
UIInteractions.simulateTyping('11/10/2015', startInput);
@@ -1138,7 +1139,7 @@ describe('IgxDateRangePicker', () => {
11381139
tick(DEBOUNCE_TIME);
11391140
fixture.detectChanges();
11401141
const rangePicker = fixture.componentInstance.dateRange;
1141-
expect((rangePicker as any).calendar.selectedDates.length).toBe(0);
1142+
expect((rangePicker as any).calendar.selectedDates.length).toBe(1);
11421143

11431144
calendar = document.getElementsByClassName(CSS_CLASS_CALENDAR)[0];
11441145
UIInteractions.triggerKeyDownEvtUponElem('Escape', calendar);

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

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -977,16 +977,20 @@ export class IgxDateRangePickerComponent extends PickerBaseDirective
977977
return;
978978
}
979979
this._setDisabledDates();
980-
const { minValue, maxValue } = this._getMinMaxDates();
981980

982981
const range: Date[] = [];
983-
if (this.value?.start && this.value?.end) {
982+
if (this.value) {
984983
const _value = this.toRangeOfDates(this.value);
985-
if (DateTimeUtil.greaterThanMaxValue(_value.start, _value.end)) {
986-
this.swapEditorDates();
984+
if (_value.start && _value.end) {
985+
if (DateTimeUtil.greaterThanMaxValue(_value.start, _value.end)) {
986+
this.swapEditorDates();
987+
}
987988
}
988-
if (this.valueInRange(this.value, minValue, maxValue)) {
989-
range.push(_value.start, _value.end);
989+
if (_value.start) {
990+
range.push(_value.start);
991+
}
992+
if (_value.end) {
993+
range.push(_value.end);
990994
}
991995
}
992996

@@ -1008,18 +1012,6 @@ export class IgxDateRangePickerComponent extends PickerBaseDirective
10081012
}
10091013
}
10101014

1011-
private valueInRange(value: DateRange, minValue?: Date, maxValue?: Date): boolean {
1012-
const _value = this.toRangeOfDates(value);
1013-
if (minValue && DateTimeUtil.lessThanMinValue(_value.start, minValue, false)) {
1014-
return false;
1015-
}
1016-
if (maxValue && DateTimeUtil.greaterThanMaxValue(_value.end, maxValue, false)) {
1017-
return false;
1018-
}
1019-
1020-
return true;
1021-
}
1022-
10231015
private extractRange(selection: Date[]): DateRange {
10241016
return {
10251017
start: selection[0] || null,

0 commit comments

Comments
 (0)