Skip to content

Commit 5663b7a

Browse files
authored
Min date as default when calendar opens - resolves #256 (#264)
1 parent 4588f6f commit 5663b7a

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

src/app/common/services/utils/utils.service.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,14 @@ export class UtilsService {
5151
}
5252

5353
// todo:: add unit test
54-
getDefaultDisplayDate(def: Moment, selected: Moment[], allowMultiSelect: boolean): Moment {
55-
if (def) {
56-
return def.clone();
54+
getDefaultDisplayDate(current: Moment,
55+
selected: Moment[],
56+
allowMultiSelect: boolean,
57+
minDate: Moment): Moment {
58+
if (current) {
59+
return current.clone();
60+
} else if (minDate && minDate.isAfter(moment())) {
61+
return minDate.clone();
5762
} else if (allowMultiSelect) {
5863
if (selected && selected[selected.length]) {
5964
return selected[selected.length].clone();

src/app/date-picker/date-picker.component.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,12 @@ export class DatePickerComponent implements OnChanges,
322322
this.currentDateView = this.displayDate
323323
? this.utilsService.convertToMoment(this.displayDate, this.componentConfig.format).clone()
324324
: this.utilsService
325-
.getDefaultDisplayDate(this.currentDateView, this.selected, this.componentConfig.allowMultiSelect);
325+
.getDefaultDisplayDate(
326+
this.currentDateView,
327+
this.selected,
328+
this.componentConfig.allowMultiSelect,
329+
this.componentConfig.min
330+
);
326331
this.inputValueType = this.utilsService.getInputType(this.inputValue, this.componentConfig.allowMultiSelect);
327332
this.dayCalendarConfig = this.dayPickerService.getDayConfigService(this.componentConfig);
328333
this.dayTimeCalendarConfig = this.dayPickerService.getDayTimeConfigService(this.componentConfig);
@@ -371,7 +376,12 @@ export class DatePickerComponent implements OnChanges,
371376
if (this.dayPickerService.isValidInputDateValue(value, this.componentConfig)) {
372377
this.selected = this.dayPickerService.convertInputValueToMomentArray(value, this.componentConfig);
373378
this.currentDateView = this.selected.length
374-
? this.utilsService.getDefaultDisplayDate(null, this.selected, this.componentConfig.allowMultiSelect)
379+
? this.utilsService.getDefaultDisplayDate(
380+
null,
381+
this.selected,
382+
this.componentConfig.allowMultiSelect,
383+
this.componentConfig.min
384+
)
375385
: this.currentDateView;
376386
} else {
377387
this._selected = this.utilsService

src/app/day-calendar/day-calendar.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class DayCalendarComponent implements OnInit, OnChanges, ControlValueAcce
123123
this.currentDateView = this.displayDate
124124
? this.utilsService.convertToMoment(this.displayDate, this.componentConfig.format).clone()
125125
: this.utilsService
126-
.getDefaultDisplayDate(this.currentDateView, this.selected, this.componentConfig.allowMultiSelect);
126+
.getDefaultDisplayDate(this.currentDateView, this.selected, this.componentConfig.allowMultiSelect, this.componentConfig.min);
127127
this.weekdays = this.dayCalendarService
128128
.generateWeekdays(this.componentConfig.firstDayOfWeek);
129129
this.inputValueType = this.utilsService.getInputType(this.inputValue, this.componentConfig.allowMultiSelect);

src/app/month-calendar/month-calendar.component.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,12 @@ export class MonthCalendarComponent implements OnInit, OnChanges, ControlValueAc
123123
this.currentDateView = this.displayDate
124124
? this.displayDate
125125
: this.utilsService
126-
.getDefaultDisplayDate(this.currentDateView, this.selected, this.componentConfig.allowMultiSelect);
126+
.getDefaultDisplayDate(
127+
this.currentDateView,
128+
this.selected,
129+
this.componentConfig.allowMultiSelect,
130+
this.componentConfig.min
131+
);
127132
this.inputValueType = this.utilsService.getInputType(this.inputValue, this.componentConfig.allowMultiSelect);
128133
this._shouldShowCurrent = this.shouldShowCurrent();
129134
}

0 commit comments

Comments
 (0)