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): improve caret management for InputNumber on step action #10405

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions projects/cdk/utils/dom/value-binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,21 @@ export function tuiValueBinding(
const el = tuiInjectElement<HTMLInputElement>();

effect(() => {
if (el.value === value()) {
return;
}

const {selectionStart, selectionEnd} = el;

el.value = value();

if (el.matches(':focus')) {
/**
* After programmatic updates of input's value, caret is automatically placed at the end –
* revert to the previous position
*/
el.setSelectionRange(selectionStart, selectionEnd);
}
});

return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,96 @@
});
});
});

describe('caret position on step action', () => {
beforeEach(async ({page}) => {
await tuiGoto(page, `${DemoRoute.InputNumber}/API?step=1&postfix=kg`);

await expect(inputNumber.textfield).toHaveValue('');
await expect(inputNumber.textfield).not.toBeFocused();
});

test('Empty unfocused textfield => Click + => Textfield is focused & Caret is placed before postfix', async () => {
await inputNumber.stepUp.click();

await expect(inputNumber.textfield).toHaveValue('1kg');
await expect(inputNumber.textfield).toHaveJSProperty(

Check failure on line 398 in projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright / macos-latest / 6 of 9

[webkit] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:394:21 › InputNumber › API › [step] prop › caret position on step action › Empty unfocused textfield => Click + => Textfield is focused & Caret is placed before postfix

1) [webkit] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:394:21 › InputNumber › API › [step] prop › caret position on step action › Empty unfocused textfield => Click + => Textfield is focused & Caret is placed before postfix Error: Timed out 5000ms waiting for expect(locator).toHaveJSProperty(expected) Locator: locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') Expected: 1 Received: 3 Call log: - expect.toHaveJSProperty with timeout 5000ms - waiting for locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') 9 × locator resolved to <input maxlength="23" tuiappearance="" tuiinputnumber="" data-focus="true" inputmode="decimal" id="tui_121601061540000" data-appearance="textfield" class="_with-buttons ng-untouched ng-dirty ng-valid"/> - unexpected value "3" 396 | 397 | await expect(inputNumber.textfield).toHaveValue('1kg'); > 398 | await expect(inputNumber.textfield).toHaveJSProperty( | ^ 399 | 'selectionStart', 400 | 1, 401 | ); at /Users/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:398:57

Check failure on line 398 in projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright / macos-latest / 6 of 9

[webkit] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:394:21 › InputNumber › API › [step] prop › caret position on step action › Empty unfocused textfield => Click + => Textfield is focused & Caret is placed before postfix

1) [webkit] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:394:21 › InputNumber › API › [step] prop › caret position on step action › Empty unfocused textfield => Click + => Textfield is focused & Caret is placed before postfix Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toHaveJSProperty(expected) Locator: locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') Expected: 1 Received: 3 Call log: - expect.toHaveJSProperty with timeout 5000ms - waiting for locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') 9 × locator resolved to <input maxlength="23" tuiappearance="" tuiinputnumber="" data-focus="true" inputmode="decimal" id="tui_121601061540000" data-appearance="textfield" class="_with-buttons ng-untouched ng-dirty ng-valid"/> - unexpected value "3" 396 | 397 | await expect(inputNumber.textfield).toHaveValue('1kg'); > 398 | await expect(inputNumber.textfield).toHaveJSProperty( | ^ 399 | 'selectionStart', 400 | 1, 401 | ); at /Users/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:398:57

Check failure on line 398 in projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright / macos-latest / 6 of 9

[webkit] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:394:21 › InputNumber › API › [step] prop › caret position on step action › Empty unfocused textfield => Click + => Textfield is focused & Caret is placed before postfix

1) [webkit] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:394:21 › InputNumber › API › [step] prop › caret position on step action › Empty unfocused textfield => Click + => Textfield is focused & Caret is placed before postfix Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toHaveJSProperty(expected) Locator: locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') Expected: 1 Received: 3 Call log: - expect.toHaveJSProperty with timeout 5000ms - waiting for locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') 9 × locator resolved to <input maxlength="23" tuiappearance="" tuiinputnumber="" data-focus="true" inputmode="decimal" id="tui_121601061540000" data-appearance="textfield" class="_with-buttons ng-untouched ng-dirty ng-valid"/> - unexpected value "3" 396 | 397 | await expect(inputNumber.textfield).toHaveValue('1kg'); > 398 | await expect(inputNumber.textfield).toHaveJSProperty( | ^ 399 | 'selectionStart', 400 | 1, 401 | ); at /Users/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:398:57
'selectionStart',
1,
);
await expect(inputNumber.textfield).toHaveJSProperty(
'selectionEnd',
1,
);
});

test('Focused textfield with postfix only => Press ArrowDown => Caret is placed before postfix', async () => {
await inputNumber.textfield.focus();
await expect(inputNumber.textfield).toHaveValue('kg');
await inputNumber.textfield.press('ArrowDown');

await expect(inputNumber.textfield).toHaveValue(`${CHAR_MINUS}1kg`);
await expect(inputNumber.textfield).toHaveJSProperty(

Check failure on line 414 in projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright / macos-latest / 6 of 9

[webkit] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:408:21 › InputNumber › API › [step] prop › caret position on step action › Focused textfield with postfix only => Press ArrowDown => Caret is placed before postfix

2) [webkit] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:408:21 › InputNumber › API › [step] prop › caret position on step action › Focused textfield with postfix only => Press ArrowDown => Caret is placed before postfix Error: Timed out 5000ms waiting for expect(locator).toHaveJSProperty(expected) Locator: locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') Expected: 2 Received: 4 Call log: - expect.toHaveJSProperty with timeout 5000ms - waiting for locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') 9 × locator resolved to <input maxlength="23" tuiappearance="" tuiinputnumber="" data-focus="true" inputmode="decimal" id="tui_121601061540000" data-appearance="textfield" class="_with-buttons ng-untouched ng-dirty ng-valid"/> - unexpected value "4" 412 | 413 | await expect(inputNumber.textfield).toHaveValue(`${CHAR_MINUS}1kg`); > 414 | await expect(inputNumber.textfield).toHaveJSProperty( | ^ 415 | 'selectionStart', 416 | 2, 417 | ); at /Users/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:414:57

Check failure on line 414 in projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright / macos-latest / 6 of 9

[webkit] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:408:21 › InputNumber › API › [step] prop › caret position on step action › Focused textfield with postfix only => Press ArrowDown => Caret is placed before postfix

2) [webkit] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:408:21 › InputNumber › API › [step] prop › caret position on step action › Focused textfield with postfix only => Press ArrowDown => Caret is placed before postfix Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toHaveJSProperty(expected) Locator: locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') Expected: 2 Received: 4 Call log: - expect.toHaveJSProperty with timeout 5000ms - waiting for locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') 9 × locator resolved to <input maxlength="23" tuiappearance="" tuiinputnumber="" data-focus="true" inputmode="decimal" id="tui_121601061540000" data-appearance="textfield" class="_with-buttons ng-untouched ng-dirty ng-valid"/> - unexpected value "4" 412 | 413 | await expect(inputNumber.textfield).toHaveValue(`${CHAR_MINUS}1kg`); > 414 | await expect(inputNumber.textfield).toHaveJSProperty( | ^ 415 | 'selectionStart', 416 | 2, 417 | ); at /Users/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:414:57

Check failure on line 414 in projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright / macos-latest / 6 of 9

[webkit] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:408:21 › InputNumber › API › [step] prop › caret position on step action › Focused textfield with postfix only => Press ArrowDown => Caret is placed before postfix

2) [webkit] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:408:21 › InputNumber › API › [step] prop › caret position on step action › Focused textfield with postfix only => Press ArrowDown => Caret is placed before postfix Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toHaveJSProperty(expected) Locator: locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') Expected: 2 Received: 4 Call log: - expect.toHaveJSProperty with timeout 5000ms - waiting for locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') 9 × locator resolved to <input maxlength="23" tuiappearance="" tuiinputnumber="" data-focus="true" inputmode="decimal" id="tui_121601061540000" data-appearance="textfield" class="_with-buttons ng-untouched ng-dirty ng-valid"/> - unexpected value "4" 412 | 413 | await expect(inputNumber.textfield).toHaveValue(`${CHAR_MINUS}1kg`); > 414 | await expect(inputNumber.textfield).toHaveJSProperty( | ^ 415 | 'selectionStart', 416 | 2, 417 | ); at /Users/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:414:57
'selectionStart',
2,
);
await expect(inputNumber.textfield).toHaveJSProperty(
'selectionEnd',
2,
);
});

describe('Keeps caret position on step', () => {
beforeEach(async () => {
await inputNumber.textfield.fill('42');

await expect(inputNumber.textfield).toHaveValue('42kg');
await expect(inputNumber.textfield).toHaveJSProperty(
'selectionStart',
2,
);
await expect(inputNumber.textfield).toHaveJSProperty(
'selectionEnd',
2,
);
await inputNumber.textfield.press('ArrowLeft');
await expect(inputNumber.textfield).toHaveJSProperty(
'selectionStart',
1,
);
await expect(inputNumber.textfield).toHaveJSProperty(
'selectionEnd',
1,
);
});

test('via button', async () => {
await inputNumber.stepUp.click();
await expect(inputNumber.textfield).toHaveValue('43kg');
await expect(inputNumber.textfield).toHaveJSProperty(

Check failure on line 451 in projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright / ubuntu-latest / 6 of 9

[chromium] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:448:25 › InputNumber › API › [step] prop › caret position on step action › Keeps caret position on step › via button

1) [chromium] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:448:25 › InputNumber › API › [step] prop › caret position on step action › Keeps caret position on step › via button Error: Timed out 5000ms waiting for expect(locator).toHaveJSProperty(expected) Locator: locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') Expected: 1 Received: 2 Call log: - expect.toHaveJSProperty with timeout 5000ms - waiting for locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') 9 × locator resolved to <input maxlength="23" tuiappearance="" tuiinputnumber="" data-focus="true" inputmode="decimal" id="tui_121601061540000" data-appearance="textfield" class="_with-buttons ng-untouched ng-dirty ng-valid"/> - unexpected value "2" 449 | await inputNumber.stepUp.click(); 450 | await expect(inputNumber.textfield).toHaveValue('43kg'); > 451 | await expect(inputNumber.textfield).toHaveJSProperty( | ^ 452 | 'selectionStart', 453 | 1, 454 | ); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:451:61

Check failure on line 451 in projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright / ubuntu-latest / 6 of 9

[chromium] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:448:25 › InputNumber › API › [step] prop › caret position on step action › Keeps caret position on step › via button

1) [chromium] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:448:25 › InputNumber › API › [step] prop › caret position on step action › Keeps caret position on step › via button Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toHaveJSProperty(expected) Locator: locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') Expected: 1 Received: 2 Call log: - expect.toHaveJSProperty with timeout 5000ms - waiting for locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') 9 × locator resolved to <input maxlength="23" tuiappearance="" tuiinputnumber="" data-focus="true" inputmode="decimal" id="tui_121601061540000" data-appearance="textfield" class="_with-buttons ng-untouched ng-dirty ng-valid"/> - unexpected value "2" 449 | await inputNumber.stepUp.click(); 450 | await expect(inputNumber.textfield).toHaveValue('43kg'); > 451 | await expect(inputNumber.textfield).toHaveJSProperty( | ^ 452 | 'selectionStart', 453 | 1, 454 | ); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:451:61

Check failure on line 451 in projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright / ubuntu-latest / 6 of 9

[chromium] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:448:25 › InputNumber › API › [step] prop › caret position on step action › Keeps caret position on step › via button

1) [chromium] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:448:25 › InputNumber › API › [step] prop › caret position on step action › Keeps caret position on step › via button Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toHaveJSProperty(expected) Locator: locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') Expected: 1 Received: 2 Call log: - expect.toHaveJSProperty with timeout 5000ms - waiting for locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') 9 × locator resolved to <input maxlength="23" tuiappearance="" tuiinputnumber="" data-focus="true" inputmode="decimal" id="tui_121601061540000" data-appearance="textfield" class="_with-buttons ng-untouched ng-dirty ng-valid"/> - unexpected value "2" 449 | await inputNumber.stepUp.click(); 450 | await expect(inputNumber.textfield).toHaveValue('43kg'); > 451 | await expect(inputNumber.textfield).toHaveJSProperty( | ^ 452 | 'selectionStart', 453 | 1, 454 | ); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:451:61

Check failure on line 451 in projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright / macos-latest / 6 of 9

[webkit] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:448:25 › InputNumber › API › [step] prop › caret position on step action › Keeps caret position on step › via button

3) [webkit] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:448:25 › InputNumber › API › [step] prop › caret position on step action › Keeps caret position on step › via button Error: Timed out 5000ms waiting for expect(locator).toHaveJSProperty(expected) Locator: locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') Expected: 1 Received: 4 Call log: - expect.toHaveJSProperty with timeout 5000ms - waiting for locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') 9 × locator resolved to <input maxlength="23" tuiappearance="" tuiinputnumber="" data-focus="true" inputmode="decimal" id="tui_121601061540000" data-appearance="textfield" class="_with-buttons ng-untouched ng-dirty ng-valid"/> - unexpected value "4" 449 | await inputNumber.stepUp.click(); 450 | await expect(inputNumber.textfield).toHaveValue('43kg'); > 451 | await expect(inputNumber.textfield).toHaveJSProperty( | ^ 452 | 'selectionStart', 453 | 1, 454 | ); at /Users/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:451:61

Check failure on line 451 in projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright / macos-latest / 6 of 9

[webkit] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:448:25 › InputNumber › API › [step] prop › caret position on step action › Keeps caret position on step › via button

3) [webkit] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:448:25 › InputNumber › API › [step] prop › caret position on step action › Keeps caret position on step › via button Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toHaveJSProperty(expected) Locator: locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') Expected: 1 Received: 4 Call log: - expect.toHaveJSProperty with timeout 5000ms - waiting for locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') 9 × locator resolved to <input maxlength="23" tuiappearance="" tuiinputnumber="" data-focus="true" inputmode="decimal" id="tui_121601061540000" data-appearance="textfield" class="_with-buttons ng-untouched ng-dirty ng-valid"/> - unexpected value "4" 449 | await inputNumber.stepUp.click(); 450 | await expect(inputNumber.textfield).toHaveValue('43kg'); > 451 | await expect(inputNumber.textfield).toHaveJSProperty( | ^ 452 | 'selectionStart', 453 | 1, 454 | ); at /Users/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:451:61

Check failure on line 451 in projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright / macos-latest / 6 of 9

[webkit] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:448:25 › InputNumber › API › [step] prop › caret position on step action › Keeps caret position on step › via button

3) [webkit] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:448:25 › InputNumber › API › [step] prop › caret position on step action › Keeps caret position on step › via button Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toHaveJSProperty(expected) Locator: locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') Expected: 1 Received: 4 Call log: - expect.toHaveJSProperty with timeout 5000ms - waiting for locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') 9 × locator resolved to <input maxlength="23" tuiappearance="" tuiinputnumber="" data-focus="true" inputmode="decimal" id="tui_121601061540000" data-appearance="textfield" class="_with-buttons ng-untouched ng-dirty ng-valid"/> - unexpected value "4" 449 | await inputNumber.stepUp.click(); 450 | await expect(inputNumber.textfield).toHaveValue('43kg'); > 451 | await expect(inputNumber.textfield).toHaveJSProperty( | ^ 452 | 'selectionStart', 453 | 1, 454 | ); at /Users/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:451:61
'selectionStart',
1,
);
await expect(inputNumber.textfield).toHaveJSProperty(
'selectionEnd',
1,
);
});

test('via keyboard arrow', async () => {
await inputNumber.textfield.press('ArrowUp');
await expect(inputNumber.textfield).toHaveValue('43kg');
await expect(inputNumber.textfield).toHaveJSProperty(

Check failure on line 464 in projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright / ubuntu-latest / 6 of 9

[chromium] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:461:25 › InputNumber › API › [step] prop › caret position on step action › Keeps caret position on step › via keyboard arrow

2) [chromium] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:461:25 › InputNumber › API › [step] prop › caret position on step action › Keeps caret position on step › via keyboard arrow Error: Timed out 5000ms waiting for expect(locator).toHaveJSProperty(expected) Locator: locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') Expected: 1 Received: 2 Call log: - expect.toHaveJSProperty with timeout 5000ms - waiting for locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') 9 × locator resolved to <input maxlength="23" tuiappearance="" tuiinputnumber="" data-focus="true" inputmode="decimal" id="tui_121601061540000" data-appearance="textfield" class="_with-buttons ng-untouched ng-dirty ng-valid"/> - unexpected value "2" 462 | await inputNumber.textfield.press('ArrowUp'); 463 | await expect(inputNumber.textfield).toHaveValue('43kg'); > 464 | await expect(inputNumber.textfield).toHaveJSProperty( | ^ 465 | 'selectionStart', 466 | 1, 467 | ); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:464:61

Check failure on line 464 in projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright / ubuntu-latest / 6 of 9

[chromium] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:461:25 › InputNumber › API › [step] prop › caret position on step action › Keeps caret position on step › via keyboard arrow

2) [chromium] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:461:25 › InputNumber › API › [step] prop › caret position on step action › Keeps caret position on step › via keyboard arrow Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toHaveJSProperty(expected) Locator: locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') Expected: 1 Received: 2 Call log: - expect.toHaveJSProperty with timeout 5000ms - waiting for locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') 9 × locator resolved to <input maxlength="23" tuiappearance="" tuiinputnumber="" data-focus="true" inputmode="decimal" id="tui_121601061540000" data-appearance="textfield" class="_with-buttons ng-untouched ng-dirty ng-valid"/> - unexpected value "2" 462 | await inputNumber.textfield.press('ArrowUp'); 463 | await expect(inputNumber.textfield).toHaveValue('43kg'); > 464 | await expect(inputNumber.textfield).toHaveJSProperty( | ^ 465 | 'selectionStart', 466 | 1, 467 | ); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:464:61

Check failure on line 464 in projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright / ubuntu-latest / 6 of 9

[chromium] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:461:25 › InputNumber › API › [step] prop › caret position on step action › Keeps caret position on step › via keyboard arrow

2) [chromium] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:461:25 › InputNumber › API › [step] prop › caret position on step action › Keeps caret position on step › via keyboard arrow Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toHaveJSProperty(expected) Locator: locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') Expected: 1 Received: 2 Call log: - expect.toHaveJSProperty with timeout 5000ms - waiting for locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') 9 × locator resolved to <input maxlength="23" tuiappearance="" tuiinputnumber="" data-focus="true" inputmode="decimal" id="tui_121601061540000" data-appearance="textfield" class="_with-buttons ng-untouched ng-dirty ng-valid"/> - unexpected value "2" 462 | await inputNumber.textfield.press('ArrowUp'); 463 | await expect(inputNumber.textfield).toHaveValue('43kg'); > 464 | await expect(inputNumber.textfield).toHaveJSProperty( | ^ 465 | 'selectionStart', 466 | 1, 467 | ); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:464:61

Check failure on line 464 in projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright / macos-latest / 6 of 9

[webkit] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:461:25 › InputNumber › API › [step] prop › caret position on step action › Keeps caret position on step › via keyboard arrow

4) [webkit] › projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:461:25 › InputNumber › API › [step] prop › caret position on step action › Keeps caret position on step › via keyboard arrow Error: Timed out 5000ms waiting for expect(locator).toHaveJSProperty(expected) Locator: locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') Expected: 1 Received: 4 Call log: - expect.toHaveJSProperty with timeout 5000ms - waiting for locator('#demo-content').locator('tui-textfield:has([tuiInputNumber])').getByRole('textbox') 9 × locator resolved to <input maxlength="23" tuiappearance="" tuiinputnumber="" data-focus="true" inputmode="decimal" id="tui_121601061540000" data-appearance="textfield" class="_with-buttons ng-untouched ng-dirty ng-valid"/> - unexpected value "4" 462 | await inputNumber.textfield.press('ArrowUp'); 463 | await expect(inputNumber.textfield).toHaveValue('43kg'); > 464 | await expect(inputNumber.textfield).toHaveJSProperty( | ^ 465 | 'selectionStart', 466 | 1, 467 | ); at /Users/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-number/input-number.pw.spec.ts:464:61
'selectionStart',
1,
);
await expect(inputNumber.textfield).toHaveJSProperty(
'selectionEnd',
1,
);
});
});
});
});

describe('[prefix] & [postfix] props', () => {
Expand Down
14 changes: 10 additions & 4 deletions projects/kit/components/input-number/input-number.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,17 @@ export class TuiInputNumber extends TuiControl<number | null> {
}

protected onStep(step: number): void {
this.textfieldValue.set(
this.formatNumber(
tuiClamp((this.value() ?? 0) + step, this.min(), this.max()),
),
const newValue = this.formatNumber(
tuiClamp((this.value() ?? 0) + step, this.min(), this.max()),
);

if (this.value() === null) {
const caretIndex = newValue.length - this.postfix().length;

setTimeout(() => this.element.setSelectionRange(caretIndex, caretIndex));
}

this.textfieldValue.set(newValue);
}

private formatNumber(value: number | null): string {
Expand Down
Loading