From 11f209e6af5e6e74827feab6ccfed5bdd9938e87 Mon Sep 17 00:00:00 2001 From: Svyatoslav Zaytsev Date: Thu, 1 Aug 2024 18:43:18 +0500 Subject: [PATCH] fix(addon-mobile): emit TuiDay on first click in mobile-calendar[single=false] --- .../mobile-calendar/mobile-calendar.component.ts | 12 +++++------- .../mobile-calendar/mobile-calendar.component.ts | 2 ++ .../mobile-calendar/mobile-calendar.template.html | 9 +++++++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/projects/addon-mobile/components/mobile-calendar/mobile-calendar.component.ts b/projects/addon-mobile/components/mobile-calendar/mobile-calendar.component.ts index f9ccaaf3ae8b..ef6c26f2f996 100644 --- a/projects/addon-mobile/components/mobile-calendar/mobile-calendar.component.ts +++ b/projects/addon-mobile/components/mobile-calendar/mobile-calendar.component.ts @@ -206,12 +206,14 @@ export class TuiMobileCalendarComponent implements AfterViewInit { this.value = day; } else if (this.isMultiValue(this.value)) { this.value = tuiImmutableUpdateInputDateMulti(this.value, day); - } else if (this.isSingleValue(this.value)) { - this.value = new TuiDayRange(day, day); + } else if (this.value instanceof TuiDay) { + this.value = TuiDayRange.sort(this.value, day); + } else if (this.value instanceof TuiDayRange && !this.value.isSingleDay) { + this.value = day; } else if (this.value instanceof TuiDayRange) { this.value = TuiDayRange.sort(this.value.from, day); } else if (!this.value) { - this.value = new TuiDayRange(day, day); + this.value = day; } } @@ -272,10 +274,6 @@ export class TuiMobileCalendarComponent implements AfterViewInit { return !(day instanceof TuiDay) && !(day instanceof TuiDayRange) && this.multi; } - private isSingleValue(day: any): day is TuiDay { - return day instanceof TuiDay || (day instanceof TuiDayRange && !day.isSingleDay); - } - private get initialYear(): number { if (!this.value) { return this.today.year; diff --git a/projects/demo/src/modules/components/mobile-calendar/mobile-calendar.component.ts b/projects/demo/src/modules/components/mobile-calendar/mobile-calendar.component.ts index e7a531a683de..181f18633e12 100644 --- a/projects/demo/src/modules/components/mobile-calendar/mobile-calendar.component.ts +++ b/projects/demo/src/modules/components/mobile-calendar/mobile-calendar.component.ts @@ -80,6 +80,8 @@ export class ExampleTuiMobileCalendarComponent { single = true; + multi = false; + readonly disabledItemHandlerVariants: ReadonlyArray> = [ ALWAYS_FALSE_HANDLER, ({day}) => day % 3 === 0, diff --git a/projects/demo/src/modules/components/mobile-calendar/mobile-calendar.template.html b/projects/demo/src/modules/components/mobile-calendar/mobile-calendar.template.html index 98195f88ed00..6c70023a485e 100644 --- a/projects/demo/src/modules/components/mobile-calendar/mobile-calendar.template.html +++ b/projects/demo/src/modules/components/mobile-calendar/mobile-calendar.template.html @@ -100,6 +100,7 @@ [disabledItemHandler]="disabledItemHandler" [max]="max" [min]="min" + [multi]="multi" [single]="single" (cancel)="documentationPropertyCancel.emitEvent($event)" (confirm)="documentationPropertyConfirm.emitEvent($event)" @@ -151,6 +152,14 @@ > Single date or a range + + Array of single dates +