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

feat(core): DropdownOpen focus item in dropdown upon opening #8112

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions projects/core/components/textfield/select.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class TuiSelect extends TuiTextfieldBase {

public focus(): void {
this.el.classList.add('_ios-fix');
// TODO: Disable focus for iOS 13 and 14
this.el.focus();
this.el.classList.remove('_ios-fix');
}
Expand Down
14 changes: 9 additions & 5 deletions projects/core/directives/dropdown/dropdown-open.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,15 @@ export class TuiDropdownOpen implements OnChanges {
}

@HostListener('click', ['$event.target'])
@HostListener('keydown.enter', ['$event.target'])
@HostListener('keydown.space', ['$event.target'])
protected onClick(target: HTMLElement): void {
if (!this.editable && this.host.contains(target)) {
this.update(!this.tuiDropdownOpen);
if (this.editable && !this.host.contains(target)) {
return;
}

this.update(!this.tuiDropdownOpen);
this.focusDropdown(false);
}

@HostListener('keydown.arrowDown', ['$event', 'false'])
Expand All @@ -121,6 +126,7 @@ export class TuiDropdownOpen implements OnChanges {
}

event.preventDefault();
this.update(true);
this.focusDropdown(up);
}

Expand Down Expand Up @@ -182,8 +188,6 @@ export class TuiDropdownOpen implements OnChanges {

private focusDropdown(previous: boolean): void {
if (!this.dropdown) {
this.update(true);

return;
}

Expand All @@ -197,6 +201,6 @@ export class TuiDropdownOpen implements OnChanges {
});

child.remove();
focusable?.focus();
focusable?.focus({preventScroll: true});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@
await example.locator('button').click();
await documentationPagePO.prepareBeforeScreenshot();
await page.keyboard.down('ArrowDown');
await page.keyboard.down('ArrowDown');
await page.waitForTimeout(100);
await page.keyboard.down('Enter');
await page.waitForTimeout(100);
await expect(page).toHaveScreenshot('03-1-data-list.png');

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

View workflow job for this annotation

GitHub Actions / playwright / (1 of 9)

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

1) [chromium] › tests/core/data-list/data-list.spec.ts:29:9 › DataList › Submenu ───────────────── Error: Screenshot comparison failed: 790663 pixels (ratio 0.66 of all image pixels) are different. Expected: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/snapshots/tests/core/data-list/data-list.spec.ts-snapshots/03-1-data-list-chromium-linux.png Received: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-core-data-list-data-list-DataList-Submenu-chromium/03-1-data-list-actual.png Diff: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-core-data-list-data-list-DataList-Submenu-chromium/03-1-data-list-diff.png Call log: - expect.toHaveScreenshot(03-1-data-list.png) with timeout 5000ms - verifying given screenshot expectation - taking page screenshot - disabled all CSS animations - waiting for fonts to load... - fonts loaded - 790663 pixels (ratio 0.66 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 - 790663 pixels (ratio 0.66 of all image pixels) are different. 41 | await page.keyboard.down('Enter'); 42 | await page.waitForTimeout(100); > 43 | await expect(page).toHaveScreenshot('03-1-data-list.png'); | ^ 44 | await page.keyboard.down('ArrowRight'); 45 | await page.keyboard.down('ArrowDown'); 46 | await page.keyboard.down('ArrowDown'); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/core/data-list/data-list.spec.ts:43:28

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

View workflow job for this annotation

GitHub Actions / playwright / (1 of 9)

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

1) [chromium] › tests/core/data-list/data-list.spec.ts:29:9 › DataList › Submenu ───────────────── Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Screenshot comparison failed: 790663 pixels (ratio 0.66 of all image pixels) are different. Expected: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/snapshots/tests/core/data-list/data-list.spec.ts-snapshots/03-1-data-list-chromium-linux.png Received: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-core-data-list-data-list-DataList-Submenu-chromium-retry1/03-1-data-list-actual.png Diff: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-core-data-list-data-list-DataList-Submenu-chromium-retry1/03-1-data-list-diff.png Call log: - expect.toHaveScreenshot(03-1-data-list.png) with timeout 5000ms - verifying given screenshot expectation - taking page screenshot - disabled all CSS animations - waiting for fonts to load... - fonts loaded - 790663 pixels (ratio 0.66 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 - 790663 pixels (ratio 0.66 of all image pixels) are different. 41 | await page.keyboard.down('Enter'); 42 | await page.waitForTimeout(100); > 43 | await expect(page).toHaveScreenshot('03-1-data-list.png'); | ^ 44 | await page.keyboard.down('ArrowRight'); 45 | await page.keyboard.down('ArrowDown'); 46 | await page.keyboard.down('ArrowDown'); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/core/data-list/data-list.spec.ts:43:28

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

View workflow job for this annotation

GitHub Actions / playwright / (1 of 9)

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

1) [chromium] › tests/core/data-list/data-list.spec.ts:29:9 › DataList › Submenu ───────────────── Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: Screenshot comparison failed: 790663 pixels (ratio 0.66 of all image pixels) are different. Expected: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/snapshots/tests/core/data-list/data-list.spec.ts-snapshots/03-1-data-list-chromium-linux.png Received: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-core-data-list-data-list-DataList-Submenu-chromium-retry2/03-1-data-list-actual.png Diff: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-core-data-list-data-list-DataList-Submenu-chromium-retry2/03-1-data-list-diff.png Call log: - expect.toHaveScreenshot(03-1-data-list.png) with timeout 5000ms - verifying given screenshot expectation - taking page screenshot - disabled all CSS animations - waiting for fonts to load... - fonts loaded - 790663 pixels (ratio 0.66 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 - 790663 pixels (ratio 0.66 of all image pixels) are different. 41 | await page.keyboard.down('Enter'); 42 | await page.waitForTimeout(100); > 43 | await expect(page).toHaveScreenshot('03-1-data-list.png'); | ^ 44 | await page.keyboard.down('ArrowRight'); 45 | await page.keyboard.down('ArrowDown'); 46 | await page.keyboard.down('ArrowDown'); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/core/data-list/data-list.spec.ts:43:28
await page.keyboard.down('ArrowRight');
await page.keyboard.down('ArrowDown');
await page.keyboard.down('ArrowDown');
Expand Down Expand Up @@ -118,7 +117,7 @@
await range.fill('04.02.2022 – 04.02.2023');
await range.press('Enter');

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

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

View workflow job for this annotation

GitHub Actions / playwright / (1 of 9)

[chromium] › tests/core/data-list/data-list.spec.ts:74:9 › DataList › Complex

2) [chromium] › tests/core/data-list/data-list.spec.ts:74:9 › DataList › Complex ───────────────── Error: Screenshot comparison failed: 9007 pixels (ratio 0.01 of all image pixels) are different. Expected: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/snapshots/tests/core/data-list/data-list.spec.ts-snapshots/08-data-list-chromium-linux.png Received: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-core-data-list-data-list-DataList-Complex-chromium/08-data-list-actual.png Diff: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-core-data-list-data-list-DataList-Complex-chromium/08-data-list-diff.png Call log: - expect.toHaveScreenshot(08-data-list.png) with timeout 5000ms - verifying given screenshot expectation - taking page screenshot - disabled all CSS animations - waiting for fonts to load... - fonts loaded - 9007 pixels (ratio 0.01 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 - 9007 pixels (ratio 0.01 of all image pixels) are different. 118 | await range.press('Enter'); 119 | > 120 | await expect(page).toHaveScreenshot('08-data-list.png'); | ^ 121 | 122 | await page.locator('[automation-id="tui-data-list-calendar-option"]').click(); 123 | await page.locator('[automation-id="tui-calendar-sheet__cell"]').nth(4).click(); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/core/data-list/data-list.spec.ts:120:28

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

View workflow job for this annotation

GitHub Actions / playwright / (1 of 9)

[chromium] › tests/core/data-list/data-list.spec.ts:74:9 › DataList › Complex

2) [chromium] › tests/core/data-list/data-list.spec.ts:74:9 › DataList › Complex ───────────────── Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Screenshot comparison failed: 9007 pixels (ratio 0.01 of all image pixels) are different. Expected: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/snapshots/tests/core/data-list/data-list.spec.ts-snapshots/08-data-list-chromium-linux.png Received: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-core-data-list-data-list-DataList-Complex-chromium-retry1/08-data-list-actual.png Diff: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-core-data-list-data-list-DataList-Complex-chromium-retry1/08-data-list-diff.png Call log: - expect.toHaveScreenshot(08-data-list.png) with timeout 5000ms - verifying given screenshot expectation - taking page screenshot - disabled all CSS animations - waiting for fonts to load... - fonts loaded - 9007 pixels (ratio 0.01 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 - 9007 pixels (ratio 0.01 of all image pixels) are different. 118 | await range.press('Enter'); 119 | > 120 | await expect(page).toHaveScreenshot('08-data-list.png'); | ^ 121 | 122 | await page.locator('[automation-id="tui-data-list-calendar-option"]').click(); 123 | await page.locator('[automation-id="tui-calendar-sheet__cell"]').nth(4).click(); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/core/data-list/data-list.spec.ts:120:28

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

View workflow job for this annotation

GitHub Actions / playwright / (1 of 9)

[chromium] › tests/core/data-list/data-list.spec.ts:74:9 › DataList › Complex

2) [chromium] › tests/core/data-list/data-list.spec.ts:74:9 › DataList › Complex ───────────────── Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: Screenshot comparison failed: 9007 pixels (ratio 0.01 of all image pixels) are different. Expected: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/snapshots/tests/core/data-list/data-list.spec.ts-snapshots/08-data-list-chromium-linux.png Received: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-core-data-list-data-list-DataList-Complex-chromium-retry2/08-data-list-actual.png Diff: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-core-data-list-data-list-DataList-Complex-chromium-retry2/08-data-list-diff.png Call log: - expect.toHaveScreenshot(08-data-list.png) with timeout 5000ms - verifying given screenshot expectation - taking page screenshot - disabled all CSS animations - waiting for fonts to load... - fonts loaded - 9007 pixels (ratio 0.01 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 - 9007 pixels (ratio 0.01 of all image pixels) are different. 118 | await range.press('Enter'); 119 | > 120 | await expect(page).toHaveScreenshot('08-data-list.png'); | ^ 121 | 122 | await page.locator('[automation-id="tui-data-list-calendar-option"]').click(); 123 | await page.locator('[automation-id="tui-calendar-sheet__cell"]').nth(4).click(); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/core/data-list/data-list.spec.ts:120:28

await page.locator('[automation-id="tui-data-list-calendar-option"]').click();
await page.locator('[automation-id="tui-calendar-sheet__cell"]').nth(4).click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,10 @@ export class TuiDataListDropdownManager implements AfterViewInit {
}

private tryToFocus(index: number): void {
const content = this.dropdowns.get(index)?.dropdownBoxRef?.location.nativeElement;
const root = this.dropdowns.get(index)?.dropdownBoxRef?.location.nativeElement;

if (!content) {
return;
}

// First item is focus trap
const focusTrap = tuiGetClosestFocusable({initial: content, root: content});
const item = tuiGetClosestFocusable({
initial: focusTrap || content,
root: content,
});

if (item) {
item.focus();
if (root) {
tuiGetClosestFocusable({initial: root, root})?.focus();
}
}
}
Loading