Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(kit): InputDate hold initial value with min/max defined #9623

Merged
merged 5 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions projects/core/constants/regexp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export const TUI_MASK_SYMBOLS_REGEXP = /[ \-_()]/g;
export const TUI_LAST_PUNCTUATION_MARK_REGEXP = /[.,\\/#!$%\\^&\\*;:{}=\\-_`~()]$/;
export const TUI_LATIN_REGEXP = /[A-z]/;
export const TUI_LATIN_AND_NUMBERS_REGEXP = /[A-z|0-9]/;
export const TUI_LETTER_REGEXP = /\p{L}/u;
2 changes: 1 addition & 1 deletion projects/demo-cypress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"typeRoots": ["../../node_modules/@types", "../../node_modules/cypress/types", "../../scripts/types"],
"types": ["cypress", "node", "cypress-real-events", "@testing-library/cypress", "ng-dev-mode"]
},
"include": ["./cypress/**/*.ts"],
"include": ["**/*.ts"],
"exclude": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,49 @@
await expect(inputDate.textfield).toHaveScreenshot('01-input-date.png');
});

test('Click `Until today`', async ({page}) => {
test('Click `Until today`, calendar not switched to large date', async ({
page,
}) => {
await tuiGoto(page, 'components/input-date/API?items$=1');

await inputDate.textfield.click();
await calendar.itemButton.click();

await inputDate.textfield.click();

await expect(inputDate.textfield).toHaveValue('Until today');
await expect(inputDate.calendar).toHaveScreenshot(
'02-input-date-calendar.png',
);
});

test('Press backspace to remove `Until today`, textfield is empty', async ({
page,
}) => {
await tuiGoto(page, 'components/input-date/API?items$=1');

await inputDate.textfield.click();
await calendar.itemButton.click();

await inputDate.textfield.focus();
await inputDate.textfield.press('Backspace');

await expect(inputDate.textfield).toHaveValue('');

Check failure on line 73 in projects/demo-playwright/tests/kit/input-date/input-date.spec.ts

View workflow job for this annotation

GitHub Actions / playwright / (3 of 4)

[chromium] › tests/kit/input-date/input-date.spec.ts:62:13 › InputDate › API › Press backspace to remove `Until today`

1) [chromium] › tests/kit/input-date/input-date.spec.ts:62:13 › InputDate › API › Press backspace to remove `Until today`, textfield is empty Error: Timed out 5000ms waiting for expect(locator).toHaveValue(expected) Locator: locator('#demo-content').locator('tui-input-date').getByRole('textbox') Expected string: "" Received string: "01.01.0000" Call log: - expect.toHaveValue with timeout 5000ms - waiting for locator('#demo-content').locator('tui-input-date').getByRole('textbox') - locator resolved to <input tabindex="0" tuimaskaccessor="" aria-invalid="false" _ngcontent-tui-demo-c171="" id="tui_interactive_561601061540000" class="t-input ng-untouched ng-valid ng-dirty" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "01.01.0000" - locator resolved to <input tabindex="0" tuimaskaccessor="" aria-invalid="false" _ngcontent-tui-demo-c171="" id="tui_interactive_561601061540000" class="t-input ng-untouched ng-valid ng-dirty" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "01.01.0000" - locator resolved to <input tabindex="0" tuimaskaccessor="" aria-invalid="false" _ngcontent-tui-demo-c171="" id="tui_interactive_561601061540000" class="t-input ng-untouched ng-valid ng-dirty" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "01.01.0000" - locator resolved to <input tabindex="0" tuimaskaccessor="" aria-invalid="false" _ngcontent-tui-demo-c171="" id="tui_interactive_561601061540000" class="t-input ng-untouched ng-valid ng-dirty" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "01.01.0000" - locator resolved to <input tabindex="0" tuimaskaccessor="" aria-invalid="false" _ngcontent-tui-demo-c171="" id="tui_interactive_561601061540000" class="t-input ng-untouched ng-valid ng-dirty" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "01.01.0000" - locator resolved to <input tabindex="0" tuimaskaccessor="" aria-invalid="false" _ngcontent-tui-demo-c171="" id="tui_interactive_561601061540000" class="t-input ng-untouched ng-valid ng-dirty" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "01.01.0000" - locator resolved to <input tabindex="0" tuimaskaccessor="" aria-invalid="false" _ngcontent-tui-demo-c171="" id="tui_interactive_561601061540000" class="t-input ng-untouched ng-valid ng-dirty" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "01.01.0000" - locator resolved to <input tabindex="0" tuimaskaccessor="" aria-invalid="false" _ngcontent-tui-demo-c171="" id="tui_interactive_561601061540000" class="t-input ng-untouched ng-valid ng-dirty" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "01.01.0000" - locator resolved to <input tabindex="0" tuimaskaccessor="" aria-invalid="false" _ngcontent-tui-demo-c171="" id="tui_interactive_561601061540000" class="t-input ng-untouched ng-valid ng-dirty" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "01.01.0000" 71 | await inputDate.textfield.press('Backspace'); 72 | > 73 | await expect(inputDate.textfield).toHaveValue(''); | ^ 74 | await expect(inputDate.textfield).toHaveScreenshot( 75 | '03-input-date-textfield-empty.png', 76 | ); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-date/input-date.spec.ts:73:47

Check failure on line 73 in projects/demo-playwright/tests/kit/input-date/input-date.spec.ts

View workflow job for this annotation

GitHub Actions / playwright / (3 of 4)

[chromium] › tests/kit/input-date/input-date.spec.ts:62:13 › InputDate › API › Press backspace to remove `Until today`

1) [chromium] › tests/kit/input-date/input-date.spec.ts:62:13 › InputDate › API › Press backspace to remove `Until today`, textfield is empty Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toHaveValue(expected) Locator: locator('#demo-content').locator('tui-input-date').getByRole('textbox') Expected string: "" Received string: "01.01.0000" Call log: - expect.toHaveValue with timeout 5000ms - waiting for locator('#demo-content').locator('tui-input-date').getByRole('textbox') - locator resolved to <input tabindex="0" tuimaskaccessor="" aria-invalid="false" _ngcontent-tui-demo-c171="" id="tui_interactive_561601061540000" class="t-input ng-untouched ng-valid ng-dirty" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "01.01.0000" - locator resolved to <input tabindex="0" tuimaskaccessor="" aria-invalid="false" _ngcontent-tui-demo-c171="" id="tui_interactive_561601061540000" class="t-input ng-untouched ng-valid ng-dirty" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "01.01.0000" - locator resolved to <input tabindex="0" tuimaskaccessor="" aria-invalid="false" _ngcontent-tui-demo-c171="" id="tui_interactive_561601061540000" class="t-input ng-untouched ng-valid ng-dirty" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "01.01.0000" - locator resolved to <input tabindex="0" tuimaskaccessor="" aria-invalid="false" _ngcontent-tui-demo-c171="" id="tui_interactive_561601061540000" class="t-input ng-untouched ng-valid ng-dirty" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "01.01.0000" - locator resolved to <input tabindex="0" tuimaskaccessor="" aria-invalid="false" _ngcontent-tui-demo-c171="" id="tui_interactive_561601061540000" class="t-input ng-untouched ng-valid ng-dirty" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "01.01.0000" - locator resolved to <input tabindex="0" tuimaskaccessor="" aria-invalid="false" _ngcontent-tui-demo-c171="" id="tui_interactive_561601061540000" class="t-input ng-untouched ng-valid ng-dirty" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "01.01.0000" - locator resolved to <input tabindex="0" tuimaskaccessor="" aria-invalid="false" _ngcontent-tui-demo-c171="" id="tui_interactive_561601061540000" class="t-input ng-untouched ng-valid ng-dirty" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "01.01.0000" - locator resolved to <input tabindex="0" tuimaskaccessor="" aria-invalid="false" _ngcontent-tui-demo-c171="" id="tui_interactive_561601061540000" class="t-input ng-untouched ng-valid ng-dirty" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "01.01.0000" - locator resolved to <input tabindex="0" tuimaskaccessor="" aria-invalid="false" _ngcontent-tui-demo-c171="" id="tui_interactive_561601061540000" class="t-input ng-untouched ng-valid ng-dirty" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "01.01.0000" 71 | await inputDate.textfield.press('Backspace'); 72 | > 73 | await expect(inputDate.textfield).toHaveValue(''); | ^ 74 | await expect(inputDate.textfield).toHaveScreenshot( 75 | '03-input-date-textfield-empty.png', 76 | ); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-date/input-date.spec.ts:73:47
await expect(inputDate.textfield).toHaveScreenshot(
'03-input-date-textfield-empty.png',
);
});

test('Enter item date, it converts to item date name', async ({page}) => {
await tuiGoto(page, 'components/input-date/API?items$=1');

await inputDate.textfield.focus();
await inputDate.textfield.fill('31.12.9998');

await expect(inputDate.textfield).toHaveValue('Until today');
await expect(inputDate.textfield).toHaveScreenshot(
'04-input-date-item-name.png',
);
});
});
});
24 changes: 21 additions & 3 deletions projects/kit/components/input-date/input-date.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
import {
TUI_DEFAULT_MARKER_HANDLER,
TUI_DROPDOWN_COMPONENT,
TUI_LETTER_REGEXP,
TUI_TEXTFIELD_SIZE,
TuiMarkerHandler,
TuiPrimitiveTextfieldComponent,
Expand Down Expand Up @@ -148,10 +149,28 @@ export class TuiInputDateComponent
}

get computedMin(): TuiDay {
/**
* 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 this.options.min;
vladimirpotekhin marked this conversation as resolved.
Show resolved Hide resolved
}

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

get computedMax(): TuiDay {
/**
* 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 this.options.max;
}

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

Expand Down Expand Up @@ -222,8 +241,7 @@ export class TuiInputDateComponent
* after solving this issue:
* https://github.com/taiga-family/maskito/issues/604
*/
const nativeValueIsNotSynced =
this.textfield?.nativeFocusableElement?.value !== this.computedValue;
const nativeValueIsNotSynced = this.nativeValue !== this.computedValue;

return this.activeItem || nativeValueIsNotSynced
? MASKITO_DEFAULT_OPTIONS
Expand Down Expand Up @@ -277,7 +295,7 @@ export class TuiInputDateComponent
}

this.value =
value.length !== DATE_FILLER_LENGTH
value.length !== DATE_FILLER_LENGTH || TUI_LETTER_REGEXP.test(value)
? null
: TuiDay.normalizeParse(value, this.dateFormat);
}
Expand Down
Loading