Skip to content

Commit

Permalink
fix(core): focus first element in data-list
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Dec 3, 2024
1 parent 84fd6e4 commit 12b6db7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
4 changes: 2 additions & 2 deletions projects/cdk/utils/focus/get-closest-focusable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ export function tuiGetClosestFocusable({

treeWalker.currentNode = initial;

while (previous ? treeWalker.previousNode() : treeWalker.nextNode()) {
do {
if (tuiIsHTMLElement(treeWalker.currentNode)) {
initial = treeWalker.currentNode;
}

if (tuiIsHTMLElement(initial) && check(initial)) {
return initial;
}
}
} while (previous ? treeWalker.previousNode() : treeWalker.nextNode());

return null;
}
23 changes: 18 additions & 5 deletions projects/demo-playwright/tests/core/data-list/data-list.pw.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,50 @@ test.describe('DataList', () => {
const example = documentationPagePO.getExample('#submenu');

await example.scrollIntoViewIfNeeded();
await example.locator('button').click();
await documentationPagePO.prepareBeforeScreenshot();

await example.locator('button').click();
await page.keyboard.down('ArrowDown');
await page.keyboard.down('ArrowDown');

await expect(page).toHaveScreenshot('03-1-data-list.png');

await page.waitForTimeout(100);
await page.keyboard.down('Enter');
await page.waitForTimeout(100);

await expect(page).toHaveScreenshot('03-1-data-list.png');
await expect(page).toHaveScreenshot('03-2-data-list.png');

await page.keyboard.down('ArrowRight');

await expect(page).toHaveScreenshot('03-3-data-list.png');

Check failure on line 55 in projects/demo-playwright/tests/core/data-list/data-list.pw.spec.ts

View workflow job for this annotation

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

[chromium] › tests/core/data-list/data-list.pw.spec.ts:31:9 › DataList › Submenu

1) [chromium] › tests/core/data-list/data-list.pw.spec.ts:31:9 › DataList › Submenu ────────────── Error: expect(page).toHaveScreenshot(expected) 101918 pixels (ratio 0.09 of all image pixels) are different. Expected: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/snapshots/tests/core/data-list/data-list.pw.spec.ts-snapshots/03-3-data-list-chromium-linux.png Received: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-core-data-list-data-list.pw-DataList-Submenu-chromium/03-3-data-list-actual.png Diff: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-core-data-list-data-list.pw-DataList-Submenu-chromium/03-3-data-list-diff.png Call log: - expect.toHaveScreenshot(03-3-data-list.png) with timeout 5000ms - verifying given screenshot expectation - taking page screenshot - disabled all CSS animations - waiting for fonts to load... - fonts loaded - 101918 pixels (ratio 0.09 of all image pixels) are different. - waiting 100ms before taking screenshot - taking page screenshot - disabled all CSS animations - waiting for fonts to load... - fonts loaded - captured a stable screenshot - 101918 pixels (ratio 0.09 of all image pixels) are different. 53 | await page.keyboard.down('ArrowRight'); 54 | > 55 | await expect(page).toHaveScreenshot('03-3-data-list.png'); | ^ 56 | 57 | await page.keyboard.down('ArrowDown'); 58 | await page.keyboard.down('ArrowDown'); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/core/data-list/data-list.pw.spec.ts:55:28

Check failure on line 55 in projects/demo-playwright/tests/core/data-list/data-list.pw.spec.ts

View workflow job for this annotation

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

[chromium] › tests/core/data-list/data-list.pw.spec.ts:31:9 › DataList › Submenu

1) [chromium] › tests/core/data-list/data-list.pw.spec.ts:31:9 › DataList › Submenu ────────────── Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(page).toHaveScreenshot(expected) 101918 pixels (ratio 0.09 of all image pixels) are different. Expected: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/snapshots/tests/core/data-list/data-list.pw.spec.ts-snapshots/03-3-data-list-chromium-linux.png Received: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-core-data-list-data-list.pw-DataList-Submenu-chromium-retry1/03-3-data-list-actual.png Diff: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-core-data-list-data-list.pw-DataList-Submenu-chromium-retry1/03-3-data-list-diff.png Call log: - expect.toHaveScreenshot(03-3-data-list.png) with timeout 5000ms - verifying given screenshot expectation - taking page screenshot - disabled all CSS animations - waiting for fonts to load... - fonts loaded - 101918 pixels (ratio 0.09 of all image pixels) are different. - waiting 100ms before taking screenshot - taking page screenshot - disabled all CSS animations - waiting for fonts to load... - fonts loaded - captured a stable screenshot - 101918 pixels (ratio 0.09 of all image pixels) are different. 53 | await page.keyboard.down('ArrowRight'); 54 | > 55 | await expect(page).toHaveScreenshot('03-3-data-list.png'); | ^ 56 | 57 | await page.keyboard.down('ArrowDown'); 58 | await page.keyboard.down('ArrowDown'); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/core/data-list/data-list.pw.spec.ts:55:28

Check failure on line 55 in projects/demo-playwright/tests/core/data-list/data-list.pw.spec.ts

View workflow job for this annotation

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

[chromium] › tests/core/data-list/data-list.pw.spec.ts:31:9 › DataList › Submenu

1) [chromium] › tests/core/data-list/data-list.pw.spec.ts:31:9 › DataList › Submenu ────────────── Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(page).toHaveScreenshot(expected) 101918 pixels (ratio 0.09 of all image pixels) are different. Expected: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/snapshots/tests/core/data-list/data-list.pw.spec.ts-snapshots/03-3-data-list-chromium-linux.png Received: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-core-data-list-data-list.pw-DataList-Submenu-chromium-retry2/03-3-data-list-actual.png Diff: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-core-data-list-data-list.pw-DataList-Submenu-chromium-retry2/03-3-data-list-diff.png Call log: - expect.toHaveScreenshot(03-3-data-list.png) with timeout 5000ms - verifying given screenshot expectation - taking page screenshot - disabled all CSS animations - waiting for fonts to load... - fonts loaded - 101918 pixels (ratio 0.09 of all image pixels) are different. - waiting 100ms before taking screenshot - taking page screenshot - disabled all CSS animations - waiting for fonts to load... - fonts loaded - captured a stable screenshot - 101918 pixels (ratio 0.09 of all image pixels) are different. 53 | await page.keyboard.down('ArrowRight'); 54 | > 55 | await expect(page).toHaveScreenshot('03-3-data-list.png'); | ^ 56 | 57 | await page.keyboard.down('ArrowDown'); 58 | await page.keyboard.down('ArrowDown'); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/core/data-list/data-list.pw.spec.ts:55:28

await page.keyboard.down('ArrowDown');
await page.keyboard.down('ArrowDown');
await page.keyboard.down('ArrowDown');

await expect(page).toHaveScreenshot('03-4-data-list.png');

await page.waitForTimeout(100);
await page.keyboard.down('Enter');
await page.waitForTimeout(100);

await expect(page).toHaveScreenshot('03-2-data-list.png');
await expect(page).toHaveScreenshot('03-5-data-list.png');

await page.keyboard.down('ArrowRight');

await expect(page).toHaveScreenshot('03-6-data-list.png');

await page.keyboard.down('ArrowDown');
await page.keyboard.down('ArrowDown');

await expect(page).toHaveScreenshot('03-3-data-list.png');
await expect(page).toHaveScreenshot('03-7-data-list.png');

await page.waitForTimeout(100);
await page.keyboard.down('Enter');
await page.waitForTimeout(100);

await expect(page).toHaveScreenshot('03-4-data-list.png');
await expect(page).toHaveScreenshot('03-8-data-list.png');
});

test('Form control', async ({page}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ export class TuiDataListDropdownManager implements AfterViewInit {
root: content,
});

if (item) {
item.focus();
}
item?.focus();
}
}

0 comments on commit 12b6db7

Please sign in to comment.