Skip to content

Commit

Permalink
fix(kit): CalendarRange revert computedMonth changes (#8909)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdlufy authored Sep 9, 2024
1 parent 4f71576 commit 848d12c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
22 changes: 7 additions & 15 deletions projects/kit/components/calendar-range/calendar-range.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,12 @@ export class TuiCalendarRange implements OnInit, OnChanges {
this.selectedPeriod = period;
}

public get computedMonth(): TuiMonth {
return this.value ? this.value.from : this.defaultViewedMonth;
}

public ngOnChanges(): void {
this.defaultViewedMonth =
(this.items.length ? this.value?.to : this.value?.from) ||
this.defaultViewedMonth;
this.initDefaultViewedMonth();
}

public ngOnInit(): void {
if (!this.value) {
this.updateDefaultViewedMonth();
}
this.initDefaultViewedMonth();
}

protected get calculatedDisabledItemHandler(): TuiBooleanHandler<TuiDay> {
Expand Down Expand Up @@ -257,12 +249,12 @@ export class TuiCalendarRange implements OnInit, OnChanges {
};
}

private updateDefaultViewedMonth(): void {
if (this.max && this.defaultViewedMonth.monthSameOrAfter(this.max)) {
private initDefaultViewedMonth(): void {
if (this.value) {
this.defaultViewedMonth = this.items.length ? this.value.to : this.value.from;
} else if (this.max && this.defaultViewedMonth.monthSameOrAfter(this.max)) {
this.defaultViewedMonth = this.max.append({month: -1});
}

if (this.min && this.defaultViewedMonth.monthSameOrBefore(this.min)) {
} else if (this.min && this.defaultViewedMonth.monthSameOrBefore(this.min)) {
this.defaultViewedMonth = this.min;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[max]="max | tuiMapper: capsMapper : value : maxLength : false"
[maxViewedMonth]="items.length ? null : (defaultViewedMonth | tuiMapper: monthOffset : -1)"
[min]="min | tuiMapper: capsMapper : value : maxLength : true"
[month]="computedMonth"
[month]="defaultViewedMonth"
[showAdjacent]="!!items.length"
[value]="value"
[(hoveredItem)]="hoveredItem"
Expand Down

0 comments on commit 848d12c

Please sign in to comment.