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 (#10250)
  • Loading branch information
mdlufy authored Jan 27, 2025
1 parent 8ead5b4 commit 1e7d185
Show file tree
Hide file tree
Showing 5 changed files with 49 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,29 @@ 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;
}

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;
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,15 @@ describe('InputDateRangeComponent', () => {
it('When entering two dates, the value is truncated by min / max is updated', () => {
testComponent.min = new TuiDay(2001, 6, 15);
testComponent.max = new TuiDay(2019, 6, 15);

fixture.detectChanges();

// min-max mask triggered only if value changed via UI (is not pristine)
testComponent.control.markAsDirty();

inputPO.sendText(`15.07.2000${RANGE_SEPARATOR_CHAR}15.07.2020`);

expect(inputPO.value).toBe('15.07.2001 – 15.07.2019');
expect(testComponent.control.value.getFormattedDayRange('DMY', '.')).toBe(
`15.07.2001${RANGE_SEPARATOR_CHAR}15.07.2019`,
);
Expand Down Expand Up @@ -376,6 +382,9 @@ describe('InputDateRangeComponent', () => {
});

it('transforms min day as output (if typed day is less than min day)', () => {
// min-max mask triggered only if value changed via UI (is not pristine)
testComponent.control.markAsDirty();

inputPO.sendText('19.02.1861-10.03.1995');

expect(inputPO.value).toBe('01.01.1900 – 10.03.1995');
Expand Down

0 comments on commit 1e7d185

Please sign in to comment.