Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dropdown): fix arrow navigation inside shadow dom (#4548)
Fixes #4540
- Loading branch information
1 parent
9cb3486
commit 995d22d
Showing
7 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
e2e-app/src/app/dropdown/shadow/dropdown-shadow.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<h3>Dropdown shadow tests</h3> | ||
|
||
<div class="input-group"> | ||
<div ngbDropdown class="d-inline-block me-3"> | ||
<button class="btn btn-outline-secondary" id="dropdown" ngbDropdownToggle>Choose and option</button> | ||
<div ngbDropdownMenu aria-labelledby="dropdown"> | ||
<button ngbDropdownItem id="item-1">One</button> | ||
<hr /> | ||
<button ngbDropdownItem disabled>Disabled</button> | ||
<button class="dropdown-item">Not arrow-focusable</button> | ||
<hr /> | ||
<button ngbDropdownItem id="item-2">Two</button> | ||
</div> | ||
</div> | ||
</div> |
12 changes: 12 additions & 0 deletions
12
e2e-app/src/app/dropdown/shadow/dropdown-shadow.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Component, ViewEncapsulation } from '@angular/core'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; | ||
import { NgIf } from '@angular/common'; | ||
|
||
@Component({ | ||
standalone: true, | ||
imports: [FormsModule, NgbModule, NgIf], | ||
templateUrl: './dropdown-shadow.component.html', | ||
encapsulation: ViewEncapsulation.ShadowDom, | ||
}) | ||
export class DropdownShadowComponent {} |
47 changes: 47 additions & 0 deletions
47
e2e-app/src/app/dropdown/shadow/dropdown-shadow.e2e-spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { expect } from '@playwright/test'; | ||
import { openDropdown } from '../dropdown.po'; | ||
import { getPage, setPage, test } from '../../../../baseTest'; | ||
import { sendKey } from '../../tools.po'; | ||
|
||
const SELECTOR_DROPDOWN = '[ngbDropdown]'; | ||
const SELECTOR_DROPDOWN_TOGGLE = '[ngbDropdownToggle]'; | ||
const SELECTOR_DROPDOWN_ITEM = (item: number) => `#item-${item}`; | ||
|
||
const focusToggle = async () => { | ||
await getPage().focus(SELECTOR_DROPDOWN_TOGGLE); | ||
await expect(getPage().locator(SELECTOR_DROPDOWN_TOGGLE), `dropdown toggle should be focused`).toBeFocused(); | ||
}; | ||
|
||
test.use({ testURL: 'dropdown/shadow', testSelector: 'h3:text("Dropdown shadow")' }); | ||
test.beforeEach(async ({ page }) => setPage(page)); | ||
|
||
test.describe(`Dropdown shadow`, () => { | ||
test(`should focus dropdown items with 'ArrowUp' / 'ArrowDown'`, async () => { | ||
// Open | ||
await openDropdown('Dropdown should be opened', SELECTOR_DROPDOWN); | ||
await expect(getPage().locator(SELECTOR_DROPDOWN_TOGGLE), `Toggling element should be focused`).toBeFocused(); | ||
|
||
// Down -> first | ||
await sendKey('ArrowDown'); | ||
await expect(getPage().locator(SELECTOR_DROPDOWN_ITEM(1)), `first dropdown item should be focused`).toBeFocused(); | ||
|
||
// Down -> second | ||
await sendKey('ArrowDown'); | ||
await expect(getPage().locator(SELECTOR_DROPDOWN_ITEM(2)), `second dropdown item should be focused`).toBeFocused(); | ||
|
||
// Down -> second | ||
await sendKey('ArrowDown'); | ||
await expect( | ||
getPage().locator(SELECTOR_DROPDOWN_ITEM(2)), | ||
`second dropdown item should stay focused`, | ||
).toBeFocused(); | ||
|
||
// Up -> first | ||
await sendKey('ArrowUp'); | ||
await expect(getPage().locator(SELECTOR_DROPDOWN_ITEM(1)), `first dropdown item should be focused`).toBeFocused(); | ||
|
||
// Up -> first | ||
await sendKey('ArrowUp'); | ||
await expect(getPage().locator(SELECTOR_DROPDOWN_ITEM(1)), `first dropdown item should stay focused`).toBeFocused(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters