Skip to content

Commit

Permalink
fix(f6navigation): skip hidden elements (#10325)
Browse files Browse the repository at this point in the history
F6 navigation was finding hidden elements, and this was stopping the navigation between groups.

Fixes: #10236
  • Loading branch information
nnaydenow authored Jan 6, 2025
1 parent a2b5f6f commit 374d4d8
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 13 deletions.
28 changes: 15 additions & 13 deletions packages/base/src/util/FocusableElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,24 @@ const findFocusableElement = async (container: HTMLElement, forward: boolean, st
while (child) {
const originalChild: HTMLElement | undefined = child;

if (instanceOfUI5Element(child)) {
child = await child.getFocusDomRefAsync();
}

if (!child) {
return null;
}
if (!isElementHidden(originalChild)) {
if (instanceOfUI5Element(child)) {
child = await child.getFocusDomRefAsync();
}

if (child.nodeType === 1 && isElemFocusable(child) && !isFocusTrap(child)) {
if (isElementClickable(child)) {
return (child && typeof child.focus === "function") ? child : null;
if (!child || isElementHidden(child)) {
return null;
}

focusableDescendant = await findFocusableElement(child, forward);
if (focusableDescendant) {
return (focusableDescendant && typeof focusableDescendant.focus === "function") ? focusableDescendant : null;
if (child.nodeType === 1 && isElemFocusable(child) && !isFocusTrap(child)) {
if (isElementClickable(child)) {
return (child && typeof child.focus === "function") ? child : null;
}

focusableDescendant = await findFocusableElement(child, forward);
if (focusableDescendant) {
return (focusableDescendant && typeof focusableDescendant.focus === "function") ? focusableDescendant : null;
}
}
}

Expand Down
134 changes: 134 additions & 0 deletions packages/main/cypress/specs/F6.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,73 @@ describe("F6 navigation", () => {
.should("be.focused");
});

it("tests navigation with hidden elements", () => {
cy.mount(html`<div>
<div class="section">
<button id="before">Before element</button>
</div>
<div class="section" data-sap-ui-fastnavgroup="true">
<ui5-button id="first">First focusable</ui5-button>
</div>
<div class="section" data-sap-ui-fastnavgroup="true">
<ui5-button style="visibility: hidden;">Hidden</ui5-button>
</div>
<div class="section" data-sap-ui-fastnavgroup="true" style="visibility: hidden;">
<ui5-button>Hidden</ui5-button>
</div>
<div class="section" data-sap-ui-fastnavgroup="true">
<ui5-button style="display: none;">Hidden</ui5-button>
</div>
<div class="section" data-sap-ui-fastnavgroup="true" style="display: none;">
<ui5-button>Hidden</ui5-button>
</div>
<div class="section">
<ui5-button>Something focusable</ui5-button>
</div>
<div class="section" data-sap-ui-fastnavgroup="true">
<ui5-button id="second">Second focusable</ui5-button>
</div>
<div class="section">
<ui5-button>Something focusable</ui5-button>
</div>
<div class="section" data-sap-ui-fastnavgroup="true">
<ui5-button id="third">Third focusable</ui5-button>
</div>
<div class="section">
<ui5-button>After Element</ui5-button>
</div>
</div`);

// act
cy.get("#before").focus();
cy.realPress("F6");

// assert 1st group is focused
cy.get("#first")
.should("be.focused");

// act
cy.realPress("F6");

// assert 2nd group is focused
cy.get("#second")
.should("be.focused");

// act
cy.realPress("F6");

// assert 3rd group is focused
cy.get("#third")
.should("be.focused");

// act
cy.realPress("F6");

// assert 1st group is focused agian
cy.get("#first")
.should("be.focused");
});

it("tests navigation with empty group", () => {
cy.mount(html`<div>
<div class="section">
Expand Down Expand Up @@ -386,6 +453,73 @@ describe("F6 navigation", () => {
.should("be.focused");
});

it("tests navigation with hidden elements", () => {
cy.mount(html`<div>
<div class="section">
<button id="before">Before element</button>
</div>
<div class="section" data-sap-ui-fastnavgroup="true">
<ui5-button id="first">First focusable</ui5-button>
</div>
<div class="section" data-sap-ui-fastnavgroup="true">
<ui5-button style="visibility: hidden;">Hidden</ui5-button>
</div>
<div class="section" data-sap-ui-fastnavgroup="true" style="visibility: hidden;">
<ui5-button>Hidden</ui5-button>
</div>
<div class="section" data-sap-ui-fastnavgroup="true">
<ui5-button style="display: none;">Hidden</ui5-button>
</div>
<div class="section" data-sap-ui-fastnavgroup="true" style="display: none;">
<ui5-button>Hidden</ui5-button>
</div>
<div class="section">
<ui5-button>Something focusable</ui5-button>
</div>
<div class="section" data-sap-ui-fastnavgroup="true">
<ui5-button id="second">Second focusable</ui5-button>
</div>
<div class="section">
<ui5-button>Something focusable</ui5-button>
</div>
<div class="section" data-sap-ui-fastnavgroup="true">
<ui5-button id="third">Third focusable</ui5-button>
</div>
<div class="section">
<ui5-button>After Element</ui5-button>
</div>
</div`);

// act
cy.get("#before").focus();
cy.realPress(["Shift", "F6"]);

// assert 3rd group is focused
cy.get("#third")
.should("be.focused");

// act
cy.realPress(["Shift", "F6"]);

// assert 2nd group is focused
cy.get("#second")
.should("be.focused");

// act
cy.realPress(["Shift", "F6"]);

// assert 1st group is focused
cy.get("#first")
.should("be.focused");

// act
cy.realPress(["Shift", "F6"]);

// assert 3rd group is focused agian
cy.get("#third")
.should("be.focused");
});

it("tests navigation with empty group", () => {
cy.mount(html`<div>
<div class="section">
Expand Down

0 comments on commit 374d4d8

Please sign in to comment.