Skip to content

Commit

Permalink
fix(kit): InputDateRange not reset initial value to min/max and sho…
Browse files Browse the repository at this point in the history
…w actual in calendar
  • Loading branch information
mdlufy committed Jan 27, 2025
1 parent 65be79b commit 388e3cc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,22 @@ test.describe('InputDateRange', () => {
'08-calendar-correct-selected-period-after-close-open.png',
);
});

test('Actual min/max in calendar', async () => {
const example = documentationPage.getExample('#base');

const inputDateRange = new TuiInputDateRangePO(
example.locator('tui-input-date-range'),
);

await inputDateRange.textfield.click();

await expect(inputDateRange.textfield).toHaveScreenshot(
'09-input-date-range-actual-min-max.png',
);
await expect(inputDateRange.calendarRange).toHaveScreenshot(
'09-input-date-range-calendar-actual-min-max.png',
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class TuiInputDateRangeExample1 {
),
});

readonly min = new TuiDay(2000, 2, 20);
readonly min = new TuiDay(2018, 2, 25);

readonly max = new TuiDay(2040, 2, 20);
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,31 @@ export class TuiInputDateRangeComponent
}

get computedMin(): TuiDay {
return this.min ?? TUI_FIRST_DAY;
/**
* TODO: we can delete this workaround in v4.0
* after solving this issue:
* https://github.com/taiga-family/maskito/issues/604
*/
if (this.value && this.control?.pristine) {
return TUI_FIRST_DAY;
}

return this.min ?? this.options.min;
// return this.min ?? TUI_FIRST_DAY;
}

get computedMax(): TuiDay {
return this.max ?? TUI_LAST_DAY;
/**
* TODO: we can delete this workaround in v4.0
* after solving this issue:
* https://github.com/taiga-family/maskito/issues/604
*/
if (this.value && this.control?.pristine) {
return TUI_LAST_DAY;
}

return this.max ?? this.options.max;
// return this.max ?? TUI_LAST_DAY;
}

get nativeFocusableElement(): HTMLInputElement | null {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
[disabledItemHandler]="disabledItemHandler"
[items]="items"
[markerHandler]="markerHandler"
[max]="computedMax"
[max]="max"
[maxLength]="maxLength"
[min]="computedMin"
[min]="min"
[minLength]="minLength"
[value]="value"
(valueChange)="onRangeChange($event)"
Expand Down

0 comments on commit 388e3cc

Please sign in to comment.