From 6ae4be388b7e76b5f1f419894bffdd087948da90 Mon Sep 17 00:00:00 2001 From: mdlufy Date: Tue, 13 Aug 2024 12:28:14 +0300 Subject: [PATCH] fix(kit): `CalendarRange` defaultViewedMonth shows correct calendars months --- .../calendar-range/calendar-range.component.ts | 3 +++ .../calendar-range.template.html | 1 + .../primitive-calendar-range.component.spec.ts | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/projects/kit/components/calendar-range/calendar-range.component.ts b/projects/kit/components/calendar-range/calendar-range.component.ts index 87ef136997fa..33bb89b6d072 100644 --- a/projects/kit/components/calendar-range/calendar-range.component.ts +++ b/projects/kit/components/calendar-range/calendar-range.component.ts @@ -120,6 +120,9 @@ export class TuiCalendarRangeComponent implements TuiWithOptionalMinMax this.value = this.previousValue; } + readonly monthOffset: TuiTypedMapper<[TuiMonth, number], TuiMonth> = (value, month) => + value.append({month}); + readonly mapper: TuiTypedMapper< [ readonly TuiDayRangePeriod[], diff --git a/projects/kit/components/calendar-range/calendar-range.template.html b/projects/kit/components/calendar-range/calendar-range.template.html index 04d7899a1284..4e984bcd3d05 100644 --- a/projects/kit/components/calendar-range/calendar-range.template.html +++ b/projects/kit/components/calendar-range/calendar-range.template.html @@ -3,6 +3,7 @@ automation-id="tui-calendar-range__calendars" tuiPreventDefault="mousedown" [defaultViewedMonthFirst]="defaultViewedMonth" + [defaultViewedMonthSecond]="defaultViewedMonth | tuiMapper: monthOffset : 1" [disabledItemHandler]="calculatedDisabledItemHandler" [markerHandler]="markerHandler" [max]="computedMax | tuiMapper: maxLengthMapper : value : maxLength : false" diff --git a/projects/kit/internal/primitive-calendar-range/test/primitive-calendar-range.component.spec.ts b/projects/kit/internal/primitive-calendar-range/test/primitive-calendar-range.component.spec.ts index 04ecbf884d90..d8c8c3e9f32e 100644 --- a/projects/kit/internal/primitive-calendar-range/test/primitive-calendar-range.component.spec.ts +++ b/projects/kit/internal/primitive-calendar-range/test/primitive-calendar-range.component.spec.ts @@ -62,6 +62,15 @@ describe('PrimitiveRangeCalendar component', () => { component.ngOnInit(); expect(component.userViewedMonthFirst).toEqual(minDate); }); + + it('When initialized input defaultViewedMonthFirst, shows defaultViewedMonthFirst', () => { + const month = new TuiMonth(2020, 5); + + component.defaultViewedMonthFirst = month; + component.ngOnInit(); + + expect(component.userViewedMonthFirst).toBe(month); + }); }); describe('viewedMonthSecond', () => { @@ -105,6 +114,15 @@ describe('PrimitiveRangeCalendar component', () => { expect(component.userViewedMonthSecond).toEqual(minDate.append({month: 1})); }); + + it('When initialized input defaultViewedMonthSecond, shows defaultViewedMonthSecond', () => { + const month = new TuiMonth(2020, 5); + + component.defaultViewedMonthSecond = month; + component.ngOnInit(); + + expect(component.userViewedMonthSecond).toBe(month); + }); }); describe('cappedUserViewedMonthSecond', () => {