Skip to content

Commit 4be8fb0

Browse files
authored
fix(kit): InputDateTime not reset initial value to min/max and show actual in calendar (#10258)
1 parent 16cb47a commit 4be8fb0

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

projects/demo-playwright/tests/kit/input-date-time/input-date-time.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,5 +274,21 @@ describe('InputDateTime', () => {
274274
{animations: 'allow'},
275275
);
276276
});
277+
278+
test('Actual min/max in calendar', async () => {
279+
example = documentationPage.getExample('#base');
280+
inputDateTime = new TuiInputDateTimePO(
281+
example.locator('tui-input-date-time'),
282+
);
283+
284+
await inputDateTime.textfield.click();
285+
286+
await expect(inputDateTime.textfield).toHaveScreenshot(
287+
'05-input-date-time-actual-min-max.png',
288+
);
289+
await expect(inputDateTime.calendar).toHaveScreenshot(
290+
'05-input-date-time-calendar-actual-min-max.png',
291+
);
292+
});
277293
});
278294
});

projects/demo/src/modules/components/input-date-time/examples/1/index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
class="b-form"
33
[formGroup]="testForm"
44
>
5-
<tui-input-date-time formControlName="testValue">
5+
<tui-input-date-time
6+
formControlName="testValue"
7+
[max]="max"
8+
[min]="min"
9+
>
610
Choose date and time
711
<input
812
placeholder="OCT 26 1985 01:22"

projects/demo/src/modules/components/input-date-time/examples/1/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ export class TuiInputDateTimeExample1 {
1414
readonly testForm = new FormGroup({
1515
testValue: new FormControl([new TuiDay(2017, 2, 15), null]),
1616
});
17+
18+
readonly min = new TuiDay(2017, 2, 25);
19+
20+
readonly max = new TuiDay(2040, 2, 20);
1721
}

projects/kit/components/input-date-time/input-date-time.component.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ import {
2121
DATE_FILLER_LENGTH,
2222
TUI_DATE_FORMAT,
2323
TUI_DATE_SEPARATOR,
24+
TUI_FIRST_DAY,
2425
TUI_IS_IOS,
2526
TUI_IS_MOBILE,
27+
TUI_LAST_DAY,
2628
TuiActiveZoneDirective,
2729
tuiAsControl,
2830
tuiAsFocusableItemAccessor,
@@ -156,10 +158,28 @@ export class TuiInputDateTimeComponent
156158
}
157159

158160
get computedMin(): TuiDay | [TuiDay, TuiTime] {
161+
/**
162+
* TODO: we can delete this workaround in v4.0
163+
* after solving this issue:
164+
* https://github.com/taiga-family/maskito/issues/604
165+
*/
166+
if (this.value && this.control?.pristine) {
167+
return TUI_FIRST_DAY;
168+
}
169+
159170
return this.toTuiDay(this.min, this.options.min);
160171
}
161172

162173
get computedMax(): TuiDay | [TuiDay, TuiTime] {
174+
/**
175+
* TODO: we can delete this workaround in v4.0
176+
* after solving this issue:
177+
* https://github.com/taiga-family/maskito/issues/604
178+
*/
179+
if (this.value && this.control?.pristine) {
180+
return TUI_LAST_DAY;
181+
}
182+
163183
return this.toTuiDay(this.max, this.options.max);
164184
}
165185

@@ -214,13 +234,13 @@ export class TuiInputDateTimeComponent
214234
}
215235

216236
get calendarMinDay(): TuiDay {
217-
const min = this.computedMin;
237+
const min = this.toTuiDay(this.min, this.options.min);
218238

219239
return Array.isArray(min) ? min[0] : min;
220240
}
221241

222242
get calendarMaxDay(): TuiDay {
223-
const max = this.computedMax;
243+
const max = this.toTuiDay(this.max, this.options.max);
224244

225245
return Array.isArray(max) ? max[0] : max;
226246
}

0 commit comments

Comments
 (0)