Skip to content

Commit

Permalink
fix(legacy): InputDateRange triggers cyclic change detection ticks (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nsbarsukov authored Aug 28, 2024
1 parent 48cc312 commit c7bc044
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export class TuiCalendarRange implements OnInit, OnChanges {
private selectedPeriod: TuiDayRangePeriod | null = null;
protected readonly otherDateText$ = inject(TUI_OTHER_DATE_TEXT);
protected readonly icons = inject(TUI_COMMON_ICONS);
protected readonly cdr = inject(ChangeDetectorRef);
protected previousValue: TuiDayRange | null = null;
protected hoveredItem: TuiDay | null = null;
protected readonly capsMapper = TUI_DAY_CAPS_MAPPER;
Expand Down Expand Up @@ -94,7 +93,7 @@ export class TuiCalendarRange implements OnInit, OnChanges {

constructor() {
inject<Observable<TuiDayRange | null>>(TUI_CALENDAR_DATE_STREAM, {optional: true})
?.pipe(tuiWatch(this.cdr), takeUntilDestroyed())
?.pipe(tuiWatch(inject(ChangeDetectorRef)), takeUntilDestroyed())
.subscribe((value) => {
this.value = value;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type {AfterViewChecked} from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
forwardRef,
inject,
Input,
ViewChild,
Expand Down Expand Up @@ -35,10 +33,7 @@ import {
import type {TuiMarkerHandler} from '@taiga-ui/core/components/calendar';
import {TUI_DATE_FORMAT, TUI_DEFAULT_DATE_FORMAT} from '@taiga-ui/core/tokens';
import type {TuiSizeL, TuiSizeS} from '@taiga-ui/core/types';
import {
TuiCalendarRange,
type TuiDayRangePeriod,
} from '@taiga-ui/kit/components/calendar-range';
import {type TuiDayRangePeriod} from '@taiga-ui/kit/components/calendar-range';
import type {TuiInputDateOptions} from '@taiga-ui/kit/tokens';
import {
TUI_DATE_RANGE_VALUE_TRANSFORMER,
Expand Down Expand Up @@ -79,14 +74,11 @@ import {map} from 'rxjs';
})
export class TuiInputDateRangeComponent
extends AbstractTuiNullableControl<TuiDayRange>
implements TuiFocusableElementAccessor, AfterViewChecked
implements TuiFocusableElementAccessor
{
@ViewChild(TuiPrimitiveTextfieldComponent)
private readonly textfield?: TuiPrimitiveTextfieldComponent;

@ViewChild(forwardRef(() => TuiCalendarRange))
private readonly calendarRange?: TuiCalendarRange;

private readonly isMobile = inject(TUI_IS_MOBILE);
private readonly mobileCalendar = inject(TUI_MOBILE_CALENDAR, {optional: true});
private readonly options = inject(TUI_INPUT_DATE_OPTIONS);
Expand Down Expand Up @@ -174,16 +166,6 @@ export class TuiInputDateRangeComponent
}
}

// TODO: remove this after refactor controls to hold whole TuiDayRangePeriod
public ngAfterViewChecked(): void {
if (this.calendarRange) {
// @ts-ignore
this.calendarRange.selectedActivePeriod = this.selectedActivePeriod;
// @ts-ignore
this.calendarRange.cdr.markForCheck();
}
}

public onValueChange(value: string): void {
if (this.control) {
this.control.updateValueAndValidity({emitEvent: false});
Expand Down Expand Up @@ -212,8 +194,6 @@ export class TuiInputDateRangeComponent
}

this.value = range;
// @ts-ignore
this.selectedActivePeriod = this.calendarRange?.selectedActivePeriod ?? null;
}

public override writeValue(value: TuiDayRange | null): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
[min]="min"
[minLength]="minLength"
[value]="value"
[(item)]="selectedActivePeriod"
(valueChange)="onRangeChange($event)"
/>
</ng-template>
Expand Down

0 comments on commit c7bc044

Please sign in to comment.