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});