Skip to content

Commit

Permalink
fix calendar range does not update checkbox position (#8488)
Browse files Browse the repository at this point in the history
Co-authored-by: Demyan Zhdanov <[email protected]>
  • Loading branch information
zhd-dm and Demyan Zhdanov authored Aug 13, 2024
1 parent 84c3aae commit e4f5bef
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e4f5bef

Please sign in to comment.