From 279baca04589ec7f03ac2ef29306fb10d3003052 Mon Sep 17 00:00:00 2001 From: dhrn Date: Thu, 19 Nov 2020 15:57:50 +0530 Subject: [PATCH 1/2] fix:- select date-time from keyboard --- projects/core/src/datetimepicker/datetimepicker-content.html | 3 ++- projects/core/src/datetimepicker/datetimepicker.ts | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/projects/core/src/datetimepicker/datetimepicker-content.html b/projects/core/src/datetimepicker/datetimepicker-content.html index 0ff51988..28382356 100644 --- a/projects/core/src/datetimepicker/datetimepicker-content.html +++ b/projects/core/src/datetimepicker/datetimepicker-content.html @@ -1,4 +1,5 @@ - implements AfterContentInit { this._calendar._focusActiveCell(); } + onSelectionChange(date: D) { + this.datetimepicker._select(date); + this.datetimepicker.close(); + } + /** * Handles keydown event on datepicker content. * @param event The event. From 162a0636c3f24a7e4c9dc7eefb6d4f58722454e2 Mon Sep 17 00:00:00 2001 From: dhrn Date: Thu, 19 Nov 2020 16:56:23 +0530 Subject: [PATCH 2/2] * prevent same date time selection fixed --- projects/core/src/datetimepicker/calendar.ts | 10 ++++++---- .../src/datetimepicker/datetimepicker-content.html | 1 + projects/core/src/datetimepicker/datetimepicker.ts | 2 ++ src/app/date.component.html | 7 +++++++ src/app/moment/moment.component.ts | 3 ++- src/app/native/native.component.ts | 3 ++- 6 files changed, 20 insertions(+), 6 deletions(-) diff --git a/projects/core/src/datetimepicker/calendar.ts b/projects/core/src/datetimepicker/calendar.ts index d7e3b323..d3b2ee63 100644 --- a/projects/core/src/datetimepicker/calendar.ts +++ b/projects/core/src/datetimepicker/calendar.ts @@ -65,6 +65,8 @@ export class MatDatetimepickerCalendar implements AfterContentInit, OnDestroy @Input() ariaPrevYearLabel = "Previous year"; @Input() ariaNextMultiYearLabel = "Next year range"; @Input() ariaPrevMultiYearLabel = "Previous year range"; + /** Prevent user to select same date time */ + @Input() preventSameDateTimeSelection = false; /** Emits when the currently selected date changes. */ @Output() selectedChange: EventEmitter = new EventEmitter(); /** Emits when the view has been changed. **/ @@ -297,7 +299,7 @@ export class MatDatetimepickerCalendar implements AfterContentInit, OnDestroy /** Handles date selection in the month view. */ _dateSelected(date: D): void { if (this.type === "date") { - if (!this._adapter.sameDate(date, this.selected)) { + if (!this._adapter.sameDate(date, this.selected) || !this.preventSameDateTimeSelection) { this.selectedChange.emit(date); } } else { @@ -309,7 +311,7 @@ export class MatDatetimepickerCalendar implements AfterContentInit, OnDestroy /** Handles month selection in the year view. */ _monthSelected(month: D): void { if (this.type === "month") { - if (!this._adapter.sameMonthAndYear(month, this.selected)) { + if (!this._adapter.sameMonthAndYear(month, this.selected) || !this.preventSameDateTimeSelection) { this.selectedChange.emit(this._adapter.getFirstDateOfMonth(month)); } } else { @@ -322,7 +324,7 @@ export class MatDatetimepickerCalendar implements AfterContentInit, OnDestroy /** Handles year selection in the multi year view. */ _yearSelected(year: D): void { if (this.type === "year") { - if (!this._adapter.sameYear(year, this.selected)) { + if (!this._adapter.sameYear(year, this.selected) || !this.preventSameDateTimeSelection) { const normalizedDate = this._adapter.createDatetime(this._adapter.getYear(year), 0, 1, 0, 0); this.selectedChange.emit(normalizedDate); } @@ -337,7 +339,7 @@ export class MatDatetimepickerCalendar implements AfterContentInit, OnDestroy this._activeDate = this._updateDate(date); this._clockView = "minute"; } else { - if (!this._adapter.sameDatetime(date, this.selected)) { + if (!this._adapter.sameDatetime(date, this.selected) || !this.preventSameDateTimeSelection) { this.selectedChange.emit(date); } } diff --git a/projects/core/src/datetimepicker/datetimepicker-content.html b/projects/core/src/datetimepicker/datetimepicker-content.html index 28382356..7af051bf 100644 --- a/projects/core/src/datetimepicker/datetimepicker-content.html +++ b/projects/core/src/datetimepicker/datetimepicker-content.html @@ -5,6 +5,7 @@ [ariaNextYearLabel]="datetimepicker.ariaNextYearLabel" [ariaPrevMonthLabel]="datetimepicker.ariaPrevMonthLabel" [ariaPrevYearLabel]="datetimepicker.ariaPrevYearLabel" + [preventSameDateTimeSelection]="datetimepicker.preventSameDateTimeSelection" [attr.mode]="datetimepicker.mode" [dateFilter]="datetimepicker._dateFilter" [id]="datetimepicker.id" diff --git a/projects/core/src/datetimepicker/datetimepicker.ts b/projects/core/src/datetimepicker/datetimepicker.ts index b5d2bc23..24867734 100644 --- a/projects/core/src/datetimepicker/datetimepicker.ts +++ b/projects/core/src/datetimepicker/datetimepicker.ts @@ -104,6 +104,8 @@ export class MatDatetimepicker implements OnDestroy { @Input() ariaPrevMonthLabel = "Previous month"; @Input() ariaNextYearLabel = "Next year"; @Input() ariaPrevYearLabel = "Previous year"; + /** Prevent user to select same date time */ + @Input() preventSameDateTimeSelection = false; /** * Emits new selected date when selected date changes. * @deprecated Switch to the `dateChange` and `dateInput` binding on the input element. diff --git a/src/app/date.component.html b/src/app/date.component.html index d9033c40..d03914af 100644 --- a/src/app/date.component.html +++ b/src/app/date.component.html @@ -85,4 +85,11 @@

Date types with: {{ type }}

+ + Prevent same date time + + + + diff --git a/src/app/moment/moment.component.ts b/src/app/moment/moment.component.ts index 41f9365c..48309ff8 100644 --- a/src/app/moment/moment.component.ts +++ b/src/app/moment/moment.component.ts @@ -87,7 +87,8 @@ export class MomentDatetimeComponent { year: [null, Validators.required], mintest: [this.today, Validators.required], filtertest: [this.today, Validators.required], - touch: [null, Validators.required] + touch: [null, Validators.required], + preventsame: [new Date("2020-11-19T17:00:00.000Z"), Validators.required] }); } } diff --git a/src/app/native/native.component.ts b/src/app/native/native.component.ts index 61698fc4..022c663b 100644 --- a/src/app/native/native.component.ts +++ b/src/app/native/native.component.ts @@ -71,7 +71,8 @@ export class NativeDatetimeComponent { year: [null, Validators.required], mintest: [this.today, Validators.required], filtertest: [this.today, Validators.required], - touch: [null, Validators.required] + touch: [null, Validators.required], + preventsame: [new Date("2020-11-19T17:00:00.000Z"), Validators.required] }); } }