From e4f5bef0bbed2e64040402c0a7728463899f55db Mon Sep 17 00:00:00 2001 From: Demyan <64752156+zhd-dm@users.noreply.github.com> Date: Tue, 13 Aug 2024 13:29:41 +0300 Subject: [PATCH] fix calendar range does not update checkbox position (#8488) Co-authored-by: Demyan Zhdanov --- .../calendar-range.component.ts | 6 +++- .../test/calendar-range.component.spec.ts | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/projects/kit/components/calendar-range/calendar-range.component.ts b/projects/kit/components/calendar-range/calendar-range.component.ts index 80378d4886e5..c48a6d2878b9 100644 --- a/projects/kit/components/calendar-range/calendar-range.component.ts +++ b/projects/kit/components/calendar-range/calendar-range.component.ts @@ -146,7 +146,11 @@ export class TuiCalendarRange implements OnInit, OnChanges { protected isItemActive(item: TuiDayRangePeriod | string): boolean { const {activePeriod} = this; - return (tuiIsString(item) && activePeriod === null) || activePeriod === item; + return ( + (tuiIsString(item) && activePeriod === null) || + activePeriod === item || + activePeriod?.toString() === item.toString() + ); } protected onItemSelect(item: TuiDayRangePeriod | string): void { diff --git a/projects/kit/components/calendar-range/test/calendar-range.component.spec.ts b/projects/kit/components/calendar-range/test/calendar-range.component.spec.ts index 2d0b71cd2235..99ab8e5d3763 100644 --- a/projects/kit/components/calendar-range/test/calendar-range.component.spec.ts +++ b/projects/kit/components/calendar-range/test/calendar-range.component.spec.ts @@ -244,6 +244,38 @@ describe('rangeCalendarComponent', () => { expect(component.defaultViewedMonth).toEqual(minDate); }); + + it('isItemActive returns true when value is set to today after being changed to yesterday', () => { + const today = TuiDay.currentLocal(); + const yesterday = today.append({day: -1}); + + testComponent.value = new TuiDayRange(today, today); + fixture.detectChanges(); + + expect( + component['isItemActive']( + new TuiDayRangePeriod(new TuiDayRange(today, today), 'Today'), + ), + ).toBe(true); + + testComponent.value = new TuiDayRange(yesterday, yesterday); + fixture.detectChanges(); + + expect( + component['isItemActive']( + new TuiDayRangePeriod(new TuiDayRange(today, today), 'Today'), + ), + ).toBe(false); + + testComponent.value = new TuiDayRange(today, today); + fixture.detectChanges(); + + expect( + component['isItemActive']( + new TuiDayRangePeriod(new TuiDayRange(today, today), 'Today'), + ), + ).toBe(true); + }); }); function getCalendar(): DebugElement | null {