From cfe33569da97b54890ba4ac4ccba644c96239aec Mon Sep 17 00:00:00 2001 From: mdlufy Date: Wed, 14 Aug 2024 14:29:51 +0300 Subject: [PATCH] fix(kit): `CalendarRange` not update `selectedActivePeriod`, when `value` updates --- .../calendar-range/calendar-range.component.ts | 13 ++++++++++++- 1 file changed, 12 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 e6ac62dcbd770..862aaef50568a 100644 --- a/projects/kit/components/calendar-range/calendar-range.component.ts +++ b/projects/kit/components/calendar-range/calendar-range.component.ts @@ -6,9 +6,11 @@ import { HostListener, Inject, Input, + OnChanges, Optional, Output, Self, + SimpleChanges, } from '@angular/core'; import { ALWAYS_FALSE_HANDLER, @@ -47,7 +49,9 @@ import {takeUntil} from 'rxjs/operators'; changeDetection: ChangeDetectionStrategy.OnPush, providers: [TuiDestroyService], }) -export class TuiCalendarRangeComponent implements TuiWithOptionalMinMax { +export class TuiCalendarRangeComponent + implements TuiWithOptionalMinMax, OnChanges +{ @Input() defaultViewedMonth: TuiMonth = TuiMonth.currentLocal(); @@ -108,6 +112,7 @@ export class TuiCalendarRangeComponent implements TuiWithOptionalMinMax valueChanges.pipe(tuiWatch(cdr), takeUntil(destroy$)).subscribe(value => { this.value = value; + this.selectedActivePeriod = null; }); } @@ -121,6 +126,12 @@ export class TuiCalendarRangeComponent implements TuiWithOptionalMinMax this.value = this.previousValue; } + ngOnChanges({value}: SimpleChanges): void { + if (value?.currentValue) { + this.selectedActivePeriod = null; + } + } + readonly monthOffset: TuiTypedMapper<[TuiMonth, number], TuiMonth> = (value, month) => value.append({month});