Skip to content

Commit 060af95

Browse files
authored
fix(f6navigation): skip non-element nodes when resolving groups (#12174)
If a fast navigation group is defined on a custom element and the first node in its shadow root is a comment, an error is thrown when looking up a focusable element. Now, lookup runs only on element nodes, skipping comments. Fixes: #12158
1 parent 6bf6727 commit 060af95

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

packages/base/src/util/FocusableElements.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const findFocusableElement = async (container: HTMLElement, forward: boolean, st
5353
let currentIndex = -1;
5454

5555
if (container.shadowRoot) {
56-
child = forward ? container.shadowRoot.firstChild as HTMLElement : container.shadowRoot.lastChild as HTMLElement;
56+
child = forward ? container.shadowRoot.firstElementChild as HTMLElement : container.shadowRoot.lastElementChild as HTMLElement;
5757
} else if (container instanceof HTMLSlotElement && container.assignedNodes()) {
5858
assignedElements = container.assignedElements();
5959
currentIndex = forward ? 0 : assignedElements.length - 1;

packages/main/cypress/specs/F6.cy.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@ import "@ui5/webcomponents-base/dist/features/F6Navigation.js";
22
import Button from "../../src/Button.js";
33
import Bar from "../../src/Bar.js";
44

5+
class MySimpleComponent extends HTMLElement {
6+
constructor() {
7+
super();
8+
this.attachShadow({ mode: "open", delegatesFocus: true });
9+
10+
this.shadowRoot.innerHTML = `
11+
<!-- HTML Comment -->
12+
<button onclick="alert('Hello!')">Click Me</button>
13+
<!-- HTML Comment -->
14+
`;
15+
}
16+
}
17+
18+
customElements.define("my-simple-component", MySimpleComponent);
19+
20+
// @ts-ignore
21+
const MySimpleComponentRenderer = () => <my-simple-component id="second" data-sap-ui-fastnavgroup="true">Second focusable</my-simple-component>
22+
523
describe("F6 navigation", () => {
624
describe("F6 Forward navigation", () => {
725
it("tests navigation", () => {
@@ -16,8 +34,8 @@ describe("F6 navigation", () => {
1634
<div class="section">
1735
<Button>Something focusable</Button>
1836
</div>
19-
<div class="section" data-sap-ui-fastnavgroup="true">
20-
<Button id="second">Second focusable</Button>
37+
<div class="section">
38+
<MySimpleComponentRenderer />
2139
</div>
2240
<div class="section">
2341
<Button>Something focusable</Button>
@@ -431,8 +449,8 @@ describe("F6 navigation", () => {
431449
<div class="section">
432450
<Button>Something focusable</Button>
433451
</div>
434-
<div class="section" data-sap-ui-fastnavgroup="true">
435-
<Button id="second">Second focusable</Button>
452+
<div class="section">
453+
<MySimpleComponentRenderer />
436454
</div>
437455
<div class="section">
438456
<Button>Something focusable</Button>

0 commit comments

Comments
 (0)